summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-03-07 05:53:17 +0000
committertb <>2023-03-07 05:53:17 +0000
commit4ed2def591bd0905eecf5872bceda17c300d15b9 (patch)
tree4d5f1e79dc42b5d1dc03278861474e458e550fab /src
parent3521badc858ffd00d9b2570c4efbe9496f2eafdf (diff)
downloadopenbsd-4ed2def591bd0905eecf5872bceda17c300d15b9.tar.gz
openbsd-4ed2def591bd0905eecf5872bceda17c300d15b9.tar.bz2
openbsd-4ed2def591bd0905eecf5872bceda17c300d15b9.zip
Basic cleanup in asn1pars.c
Drop extra parentheses, unwrap some lines, compare pointers against NULL.
Diffstat (limited to 'src')
-rw-r--r--src/usr.bin/openssl/asn1pars.c42
1 files changed, 16 insertions, 26 deletions
diff --git a/src/usr.bin/openssl/asn1pars.c b/src/usr.bin/openssl/asn1pars.c
index 5824b0ea14..d6364b5564 100644
--- a/src/usr.bin/openssl/asn1pars.c
+++ b/src/usr.bin/openssl/asn1pars.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1pars.c,v 1.13 2023/03/06 14:32:05 tb Exp $ */ 1/* $OpenBSD: asn1pars.c,v 1.14 2023/03/07 05:53:17 tb 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 *
@@ -267,7 +267,7 @@ asn1parse_main(int argc, char **argv)
267 267
268 in = BIO_new(BIO_s_file()); 268 in = BIO_new(BIO_s_file());
269 out = BIO_new(BIO_s_file()); 269 out = BIO_new(BIO_s_file());
270 if ((in == NULL) || (out == NULL)) { 270 if (in == NULL || out == NULL) {
271 ERR_print_errors(bio_err); 271 ERR_print_errors(bio_err);
272 goto end; 272 goto end;
273 } 273 }
@@ -291,8 +291,8 @@ asn1parse_main(int argc, char **argv)
291 } 291 }
292 } 292 }
293 293
294 if (cfg.derfile) { 294 if (cfg.derfile != NULL) {
295 if (!(derout = BIO_new_file(cfg.derfile, "wb"))) { 295 if ((derout = BIO_new_file(cfg.derfile, "wb")) == NULL) {
296 BIO_printf(bio_err, "problems opening %s\n", 296 BIO_printf(bio_err, "problems opening %s\n",
297 cfg.derfile); 297 cfg.derfile);
298 ERR_print_errors(bio_err); 298 ERR_print_errors(bio_err);
@@ -302,17 +302,15 @@ asn1parse_main(int argc, char **argv)
302 if ((buf = BUF_MEM_new()) == NULL) 302 if ((buf = BUF_MEM_new()) == NULL)
303 goto end; 303 goto end;
304 if (!BUF_MEM_grow(buf, BUFSIZ * 8)) 304 if (!BUF_MEM_grow(buf, BUFSIZ * 8))
305 goto end; /* Pre-allocate :-) */ 305 goto end;
306 306
307 if (cfg.genstr || cfg.genconf) { 307 if (cfg.genstr != NULL || cfg.genconf) {
308 num = do_generate(bio_err, cfg.genstr, 308 num = do_generate(bio_err, cfg.genstr, cfg.genconf, buf);
309 cfg.genconf, buf);
310 if (num < 0) { 309 if (num < 0) {
311 ERR_print_errors(bio_err); 310 ERR_print_errors(bio_err);
312 goto end; 311 goto end;
313 } 312 }
314 } else { 313 } else {
315
316 if (cfg.informat == FORMAT_PEM) { 314 if (cfg.informat == FORMAT_PEM) {
317 BIO *tmp; 315 BIO *tmp;
318 316
@@ -337,21 +335,18 @@ asn1parse_main(int argc, char **argv)
337 335
338 /* If any structs to parse go through in sequence */ 336 /* If any structs to parse go through in sequence */
339 337
340 if (sk_OPENSSL_STRING_num(cfg.osk)) { 338 if (sk_OPENSSL_STRING_num(cfg.osk) > 0) {
341 tmpbuf = (unsigned char *) str; 339 tmpbuf = (unsigned char *) str;
342 tmplen = num; 340 tmplen = num;
343 for (i = 0; i < sk_OPENSSL_STRING_num(cfg.osk); 341 for (i = 0; i < sk_OPENSSL_STRING_num(cfg.osk); i++) {
344 i++) {
345 ASN1_TYPE *atmp; 342 ASN1_TYPE *atmp;
346 int typ; 343 int typ;
347 j = strtonum( 344 j = strtonum(sk_OPENSSL_STRING_value(cfg.osk, i),
348 sk_OPENSSL_STRING_value(cfg.osk, i),
349 1, INT_MAX, &errstr); 345 1, INT_MAX, &errstr);
350 if (errstr) { 346 if (errstr) {
351 BIO_printf(bio_err, 347 BIO_printf(bio_err,
352 "'%s' is an invalid number: %s\n", 348 "'%s' is an invalid number: %s\n",
353 sk_OPENSSL_STRING_value(cfg.osk, 349 sk_OPENSSL_STRING_value(cfg.osk, i), errstr);
354 i), errstr);
355 continue; 350 continue;
356 } 351 }
357 tmpbuf += j; 352 tmpbuf += j;
@@ -366,8 +361,7 @@ asn1parse_main(int argc, char **argv)
366 goto end; 361 goto end;
367 } 362 }
368 typ = ASN1_TYPE_get(at); 363 typ = ASN1_TYPE_get(at);
369 if ((typ == V_ASN1_OBJECT) || 364 if (typ == V_ASN1_OBJECT || typ == V_ASN1_NULL) {
370 (typ == V_ASN1_NULL)) {
371 BIO_printf(bio_err, "Can't parse %s type\n", 365 BIO_printf(bio_err, "Can't parse %s type\n",
372 typ == V_ASN1_NULL ? "NULL" : "OBJECT"); 366 typ == V_ASN1_NULL ? "NULL" : "OBJECT");
373 ERR_print_errors(bio_err); 367 ERR_print_errors(bio_err);
@@ -386,10 +380,9 @@ asn1parse_main(int argc, char **argv)
386 } 380 }
387 num -= cfg.offset; 381 num -= cfg.offset;
388 382
389 if ((cfg.length == 0) || 383 if (cfg.length == 0 || (long)cfg.length > num)
390 ((long)cfg.length > num))
391 cfg.length = (unsigned int) num; 384 cfg.length = (unsigned int) num;
392 if (derout) { 385 if (derout != NULL) {
393 if (BIO_write(derout, str + cfg.offset, 386 if (BIO_write(derout, str + cfg.offset,
394 cfg.length) != (int)cfg.length) { 387 cfg.length) != (int)cfg.length) {
395 BIO_printf(bio_err, "Error writing output\n"); 388 BIO_printf(bio_err, "Error writing output\n");
@@ -397,11 +390,8 @@ asn1parse_main(int argc, char **argv)
397 goto end; 390 goto end;
398 } 391 }
399 } 392 }
400 if (!cfg.noout && 393 if (!cfg.noout && !ASN1_parse_dump(out,
401 !ASN1_parse_dump(out, 394 (unsigned char *)&str[cfg.offset], cfg.length, cfg.indent, cfg.dump)) {
402 (unsigned char *)&(str[cfg.offset]),
403 cfg.length, cfg.indent,
404 cfg.dump)) {
405 ERR_print_errors(bio_err); 395 ERR_print_errors(bio_err);
406 goto end; 396 goto end;
407 } 397 }