diff options
| author | jsing <> | 2015-04-14 10:54:40 +0000 |
|---|---|---|
| committer | jsing <> | 2015-04-14 10:54:40 +0000 |
| commit | c2c68c9ec2b9a1c26e1110762533c477c5fb045d (patch) | |
| tree | 883e043929321e3e270f44073193c520a72cdae2 | |
| parent | 9e5449cf7393dc2a7d913ea3b952fd117882b4d3 (diff) | |
| download | openbsd-c2c68c9ec2b9a1c26e1110762533c477c5fb045d.tar.gz openbsd-c2c68c9ec2b9a1c26e1110762533c477c5fb045d.tar.bz2 openbsd-c2c68c9ec2b9a1c26e1110762533c477c5fb045d.zip | |
Clean up and improve openssl(1) errstr:
- Use BIO_new_fp() instead of BIO_new()/BIO_set_fp() and handle NULL
return value in a more appropriate manner.
- Use stroul() instead of sscanf() with appropriate error checking.
ok doug@
| -rw-r--r-- | src/usr.bin/openssl/errstr.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/src/usr.bin/openssl/errstr.c b/src/usr.bin/openssl/errstr.c index 16d3832c88..9a9c844c6a 100644 --- a/src/usr.bin/openssl/errstr.c +++ b/src/usr.bin/openssl/errstr.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: errstr.c,v 1.2 2015/04/13 15:02:23 jsing Exp $ */ | 1 | /* $OpenBSD: errstr.c,v 1.3 2015/04/14 10:54:40 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -56,6 +56,7 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <limits.h> | ||
| 59 | #include <stdio.h> | 60 | #include <stdio.h> |
| 60 | #include <stdlib.h> | 61 | #include <stdlib.h> |
| 61 | #include <string.h> | 62 | #include <string.h> |
| @@ -93,10 +94,11 @@ int errstr_main(int, char **); | |||
| 93 | int | 94 | int |
| 94 | errstr_main(int argc, char **argv) | 95 | errstr_main(int argc, char **argv) |
| 95 | { | 96 | { |
| 96 | int i, ret = 0; | 97 | unsigned long ulval; |
| 98 | char *ularg, *ep; | ||
| 99 | int argsused, i; | ||
| 97 | char buf[256]; | 100 | char buf[256]; |
| 98 | unsigned long l; | 101 | int ret = 0; |
| 99 | int argsused; | ||
| 100 | 102 | ||
| 101 | memset(&errstr_config, 0, sizeof(errstr_config)); | 103 | memset(&errstr_config, 0, sizeof(errstr_config)); |
| 102 | 104 | ||
| @@ -106,30 +108,35 @@ errstr_main(int argc, char **argv) | |||
| 106 | } | 108 | } |
| 107 | 109 | ||
| 108 | if (errstr_config.stats) { | 110 | if (errstr_config.stats) { |
| 109 | BIO *out = NULL; | 111 | BIO *out; |
| 110 | 112 | ||
| 111 | out = BIO_new(BIO_s_file()); | 113 | if ((out = BIO_new_fp(stdout, BIO_NOCLOSE)) == NULL) { |
| 112 | if ((out != NULL) && BIO_set_fp(out, stdout, BIO_NOCLOSE)) { | 114 | fprintf(stderr, "Out of memory"); |
| 113 | lh_ERR_STRING_DATA_node_stats_bio( | 115 | return (1); |
| 114 | ERR_get_string_table(), out); | ||
| 115 | lh_ERR_STRING_DATA_stats_bio(ERR_get_string_table(), | ||
| 116 | out); | ||
| 117 | lh_ERR_STRING_DATA_node_usage_stats_bio( | ||
| 118 | ERR_get_string_table(), out); | ||
| 119 | } | 116 | } |
| 120 | if (out != NULL) | 117 | |
| 121 | BIO_free_all(out); | 118 | lh_ERR_STRING_DATA_node_stats_bio(ERR_get_string_table(), out); |
| 119 | lh_ERR_STRING_DATA_stats_bio(ERR_get_string_table(), out); | ||
| 120 | lh_ERR_STRING_DATA_node_usage_stats_bio( | ||
| 121 | ERR_get_string_table(), out); | ||
| 122 | |||
| 123 | BIO_free_all(out); | ||
| 122 | } | 124 | } |
| 123 | 125 | ||
| 124 | for (i = argsused; i < argc; i++) { | 126 | for (i = argsused; i < argc; i++) { |
| 125 | if (sscanf(argv[i], "%lx", &l)) { | 127 | errno = 0; |
| 126 | ERR_error_string_n(l, buf, sizeof buf); | 128 | ularg = argv[i]; |
| 127 | printf("%s\n", buf); | 129 | ulval = strtoul(ularg, &ep, 16); |
| 128 | } else { | 130 | if (strchr(ularg, '-') != NULL || |
| 129 | printf("%s: bad error code\n", argv[i]); | 131 | (ularg[0] == '\0' || *ep != '\0') || |
| 130 | errstr_usage(); | 132 | (errno == ERANGE && ulval == ULONG_MAX)) { |
| 133 | printf("%s: bad error code\n", ularg); | ||
| 131 | ret++; | 134 | ret++; |
| 135 | continue; | ||
| 132 | } | 136 | } |
| 137 | |||
| 138 | ERR_error_string_n(ulval, buf, sizeof(buf)); | ||
| 139 | printf("%s\n", buf); | ||
| 133 | } | 140 | } |
| 134 | 141 | ||
| 135 | return (ret); | 142 | return (ret); |
