From 80b1cbc3d33e30560e8230ace4bb852c0830f4a9 Mon Sep 17 00:00:00 2001 From: jsing Date: Wed, 16 Apr 2014 16:34:09 +0000 Subject: [PATCH] More KNF. --- lib/libssl/src/apps/app_rand.c | 122 +++++++++++++++++---------------- lib/libssl/src/apps/apps.c | 97 +++++++++++++++----------- 2 files changed, 119 insertions(+), 100 deletions(-) diff --git a/lib/libssl/src/apps/app_rand.c b/lib/libssl/src/apps/app_rand.c index 66e47c417cd..59fab2e269b 100644 --- a/lib/libssl/src/apps/app_rand.c +++ b/lib/libssl/src/apps/app_rand.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. - * + * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from + * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -63,7 +63,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -119,76 +119,78 @@ static int seeded = 0; static int egdsocket = 0; -int app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn) - { +int +app_RAND_load_file(const char *file, BIO *bio_e, int dont_warn) +{ int consider_randfile = (file == NULL); char buffer[200]; - + if (file == NULL) file = RAND_file_name(buffer, sizeof buffer); - else if (RAND_egd(file) > 0) - { + else if (RAND_egd(file) > 0) { /* we try if the given filename is an EGD socket. if it is, we don't write anything back to the file. */ egdsocket = 1; return 1; - } - if (file == NULL || !RAND_load_file(file, -1)) - { - if (RAND_status() == 0) - { - if (!dont_warn) - { - BIO_printf(bio_e,"unable to load 'random state'\n"); - BIO_printf(bio_e,"This means that the random number generator has not been seeded\n"); - BIO_printf(bio_e,"with much random data.\n"); + } + if (file == NULL || !RAND_load_file(file, -1)) { + if (RAND_status() == 0) { + if (!dont_warn) { + BIO_printf(bio_e, "unable to load 'random state'\n"); + BIO_printf(bio_e, "This means that the random number generator has not been seeded\n"); + BIO_printf(bio_e, "with much random data.\n"); if (consider_randfile) /* explanation does not apply when a file is explicitly named */ - { - BIO_printf(bio_e,"Consider setting the RANDFILE environment variable to point at a file that\n"); - BIO_printf(bio_e,"'random' data can be kept in (the file will be overwritten).\n"); - } + { + BIO_printf(bio_e, "Consider setting the RANDFILE environment variable to point at a file that\n"); + BIO_printf(bio_e, "'random' data can be kept in (the file will be overwritten).\n"); } - return 0; } + return 0; } + } seeded = 1; return 1; - } +} -long app_RAND_load_files(char *name) - { - char *p,*n; +long +app_RAND_load_files(char *name) +{ + char *p, *n; int last; - long tot=0; + long tot = 0; int egd; - - for (;;) - { - last=0; - for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++); - if (*p == '\0') last=1; - *p='\0'; - n=name; - name=p+1; - if (*n == '\0') break; - egd=RAND_egd(n); + for (;;) { + last = 0; + for (p = name; + ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++); + if (*p == '\0') + last = 1; + *p = '\0'; + n = name; + name = p + 1; + if (*n == '\0') + break; + + egd = RAND_egd(n); if (egd > 0) - tot+=egd; + tot += egd; else - tot+=RAND_load_file(n,-1); - if (last) break; - } + tot += RAND_load_file(n, -1); + if (last) + break; + } if (tot > 512) app_RAND_allow_write_file(); - return(tot); - } + return (tot); +} -int app_RAND_write_file(const char *file, BIO *bio_e) - { +int +app_RAND_write_file(const char *file, BIO *bio_e) +{ char buffer[200]; - + if (egdsocket || !seeded) /* If we did not manage to read the seed file, * we should not write a low-entropy seed file back -- @@ -198,15 +200,15 @@ int app_RAND_write_file(const char *file, BIO *bio_e) if (file == NULL) file = RAND_file_name(buffer, sizeof buffer); - if (file == NULL || !RAND_write_file(file)) - { - BIO_printf(bio_e,"unable to write 'random state'\n"); + if (file == NULL || !RAND_write_file(file)) { + BIO_printf(bio_e, "unable to write 'random state'\n"); return 0; - } - return 1; } + return 1; +} -void app_RAND_allow_write_file(void) - { +void +app_RAND_allow_write_file(void) +{ seeded = 1; - } +} diff --git a/lib/libssl/src/apps/apps.c b/lib/libssl/src/apps/apps.c index 47347678e5b..8a657547952 100644 --- a/lib/libssl/src/apps/apps.c +++ b/lib/libssl/src/apps/apps.c @@ -191,21 +191,24 @@ args_from_file(char *file, int *argc, char **argv[]) *argc = 0; *argv = NULL; - if (buf != NULL) OPENSSL_free(buf); - buf = (char *)OPENSSL_malloc(len + 1); + if (buf != NULL) + OPENSSL_free(buf); + buf = (char *)OPENSSL_malloc(len + 1); if (buf == NULL) return (0); len = fread(buf, 1, len, fp); - if (len <= 1) return (0); - buf[len] = '\0'; + if (len <= 1) + return (0); + buf[len] = '\0'; i = 0; for (p = buf; *p; p++) if (*p == '\n') i++; - if (arg != NULL) OPENSSL_free(arg); - arg = (char **)OPENSSL_malloc(sizeof(char *)*(i*2)); + if (arg != NULL) + OPENSSL_free(arg); + arg = (char **)OPENSSL_malloc(sizeof(char *)*(i*2)); *argv = arg; num = 0; @@ -384,7 +387,7 @@ chopup_args(ARGS *arg, char *buf, int *argc, char **argv[]) if ((*p == '\'') || (*p == '\"')) /* scan for closing quote */ { i= *(p++); - arg->data[num-1]++; /* jump over quote */ + arg->data[num - 1]++; /* jump over quote */ while (*p && (*p != i)) p++; *p = '\0'; @@ -448,7 +451,7 @@ ui_read(UI *ui, UI_STRING *uis) case UIT_VERIFY: { const char *password = - ((PW_CB_DATA *)UI_get0_user_data(ui))->password; + ((PW_CB_DATA *)UI_get0_user_data(ui))->password; if (password && password[0] != '\0') { UI_set_result(ui, uis, password); return 1; @@ -590,18 +593,23 @@ int app_passwd(BIO *err, char *arg1, char *arg2, char **pass1, char **pass2) { int same; - if (!arg2 || !arg1 || strcmp(arg1, arg2)) same = 0; - else + if (!arg2 || !arg1 || strcmp(arg1, arg2)) + same = 0; + else same = 1; if (arg1) { *pass1 = app_get_pass(err, arg1, same); - if (!*pass1) return 0; - } else if (pass1) *pass1 = NULL; - if (arg2) { + if (!*pass1) + return 0; + } else if (pass1) + *pass1 = NULL; + if (arg2) { *pass2 = app_get_pass(err, arg2, same ? 2 : 0); - if (!*pass2) return 0; - } else if (pass2) *pass2 = NULL; - return 1; + if (!*pass2) + return 0; + } else if (pass2) + *pass2 = NULL; + return 1; } static char * @@ -639,7 +647,8 @@ app_get_pass(BIO *err, char *arg, int keepbio) } else if (!strncmp(arg, "fd:", 3)) { BIO *btmp; i = atoi(arg + 3); - if (i >= 0) pwdbio = BIO_new_fd(i, BIO_NOCLOSE); + if (i >= 0) + pwdbio = BIO_new_fd(i, BIO_NOCLOSE); if ((i < 0) || !pwdbio) { BIO_printf(err, "Can't access file descriptor %s\n", arg + 3); return NULL; @@ -669,8 +678,9 @@ app_get_pass(BIO *err, char *arg, int keepbio) return NULL; } tmp = strchr(tpass, '\n'); - if (tmp) *tmp = 0; - return BUF_strdup(tpass); + if (tmp) + *tmp = 0; + return BUF_strdup(tpass); } int @@ -790,7 +800,7 @@ load_cert(BIO *err, const char *file, int format, const char *pass, ENGINE *e, (pem_password_cb *)password_callback, NULL); else if (format == FORMAT_PKCS12) { if (!load_pkcs12(err, cert, cert_descrip, NULL, NULL, - NULL, &x, NULL)) + NULL, &x, NULL)) goto end; } else { BIO_printf(err, "bad input format specified for %s\n", @@ -802,8 +812,9 @@ end: BIO_printf(err, "unable to load certificate\n"); ERR_print_errors(err); } - if (cert != NULL) BIO_free(cert); - return (x); + if (cert != NULL) + BIO_free(cert); + return (x); } EVP_PKEY * @@ -978,9 +989,10 @@ load_pubkey(BIO *err, const char *file, int format, int maybe_stdin, goto end; } end: - if (key != NULL) BIO_free(key); - if (pkey == NULL) - BIO_printf(err, "unable to load %s\n", key_descrip); + if (key != NULL) + BIO_free(key); + if (pkey == NULL) + BIO_printf(err, "unable to load %s\n", key_descrip); return (pkey); } @@ -1273,8 +1285,9 @@ set_multi_opts(unsigned long *flags, const char *arg, const NAME_EX_TBL *in_tbl) STACK_OF(CONF_VALUE) *vals; CONF_VALUE *val; int i, ret = 1; - if (!arg) return 0; - vals = X509V3_parse_list(arg); + if (!arg) + return 0; + vals = X509V3_parse_list(arg); for (i = 0; i < sk_CONF_VALUE_num(vals); i++) { val = sk_CONF_VALUE_value(vals, i); if (!set_table_opts(flags, val->name, in_tbl)) @@ -1560,9 +1573,11 @@ load_serial(char *serialfile, int create, ASN1_INTEGER **retai) ai = NULL; } err: - if (in != NULL) BIO_free(in); - if (ai != NULL) ASN1_INTEGER_free(ai); - return (ret); + if (in != NULL) + BIO_free(in); + if (ai != NULL) + ASN1_INTEGER_free(ai); + return (ret); } int @@ -1934,8 +1949,9 @@ void free_index(CA_DB *db) { if (db) { - if (db->db) TXT_DB_free(db->db); - OPENSSL_free(db); + if (db->db) + TXT_DB_free(db->db); + OPENSSL_free(db); } } @@ -2641,8 +2657,9 @@ WIN32_rename(const char *from, const char *to) err: ret = -1; ok: - if (tfrom != NULL && tfrom != (TCHAR *)from) free(tfrom); - return ret; + if (tfrom != NULL && tfrom != (TCHAR *)from) + free(tfrom); + return ret; } #endif @@ -2662,10 +2679,11 @@ app_tminterval(int stop, int usertime) if (check_winnt()) proc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId()); - if (proc == NULL) proc = (HANDLE) - 1; - } + if (proc == NULL) + proc = (HANDLE) - 1; + } - if (usertime && proc != (HANDLE) - 1) { + if (usertime && proc != (HANDLE) - 1) { FILETIME junk; GetProcessTimes(proc, &junk, &junk, &junk, &now); } else @@ -2685,8 +2703,7 @@ app_tminterval(int stop, int usertime) if (stop == TM_START) { tmstart.u.LowPart = now.dwLowDateTime; tmstart.u.HighPart = now.dwHighDateTime; - } - else { + } else { ULARGE_INTEGER tmstop; tmstop.u.LowPart = now.dwLowDateTime; @@ -2817,7 +2834,7 @@ app_tminterval(int stop, int usertime) tmstart = now; else ret = ((now.tv_sec + now.tv_usec * 1e-6) - - (tmstart.tv_sec + tmstart.tv_usec * 1e-6) ); + (tmstart.tv_sec + tmstart.tv_usec * 1e-6)); return ret; } -- 2.20.1