diff options
| author | tb <> | 2026-01-31 08:59:38 +0000 |
|---|---|---|
| committer | tb <> | 2026-01-31 08:59:38 +0000 |
| commit | 849e792a41a5662d201463e53b735b17ae516afa (patch) | |
| tree | 441069b118209f6c9ae68406ff14e2cbdd3eff19 | |
| parent | 638e4f9b1442547b8847e1f03dd2903f1eedb08b (diff) | |
| download | openbsd-849e792a41a5662d201463e53b735b17ae516afa.tar.gz openbsd-849e792a41a5662d201463e53b735b17ae516afa.tar.bz2 openbsd-849e792a41a5662d201463e53b735b17ae516afa.zip | |
openssl asn1pars: avoid a few unnecessary casts
If str is a const unsigned char * rather than a char *, we can get away
with a single cast and do not need to cast away const either. Reduce the
scope of tmpbuf and ctmpbuf (now p) while there.
ok kenjiro
| -rw-r--r-- | src/usr.bin/openssl/asn1pars.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/usr.bin/openssl/asn1pars.c b/src/usr.bin/openssl/asn1pars.c index 52991c392e..dd509d26d7 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.18 2025/11/27 08:22:32 tb Exp $ */ | 1 | /* $OpenBSD: asn1pars.c,v 1.19 2026/01/31 08:59:38 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 | * |
| @@ -239,10 +239,8 @@ asn1parse_main(int argc, char **argv) | |||
| 239 | int i, j, ret = 1; | 239 | int i, j, ret = 1; |
| 240 | long num, tmplen; | 240 | long num, tmplen; |
| 241 | BIO *in = NULL, *out = NULL, *b64 = NULL, *derout = NULL; | 241 | BIO *in = NULL, *out = NULL, *b64 = NULL, *derout = NULL; |
| 242 | char *str = NULL; | ||
| 243 | const char *errstr = NULL; | 242 | const char *errstr = NULL; |
| 244 | const unsigned char *tmpbuf; | 243 | const unsigned char *str; |
| 245 | const unsigned char *ctmpbuf; | ||
| 246 | BUF_MEM *buf = NULL; | 244 | BUF_MEM *buf = NULL; |
| 247 | ASN1_TYPE *at = NULL; | 245 | ASN1_TYPE *at = NULL; |
| 248 | 246 | ||
| @@ -330,12 +328,14 @@ asn1parse_main(int argc, char **argv) | |||
| 330 | num += i; | 328 | num += i; |
| 331 | } | 329 | } |
| 332 | } | 330 | } |
| 333 | str = buf->data; | 331 | str = (const unsigned char *)buf->data; |
| 334 | 332 | ||
| 335 | /* If any structs to parse go through in sequence */ | 333 | /* If any structs to parse go through in sequence */ |
| 336 | 334 | ||
| 337 | if (sk_OPENSSL_STRING_num(cfg.osk) > 0) { | 335 | if (sk_OPENSSL_STRING_num(cfg.osk) > 0) { |
| 338 | tmpbuf = (unsigned char *) str; | 336 | const unsigned char *tmpbuf = str; |
| 337 | const unsigned char *p; | ||
| 338 | |||
| 339 | tmplen = num; | 339 | tmplen = num; |
| 340 | for (i = 0; i < sk_OPENSSL_STRING_num(cfg.osk); i++) { | 340 | for (i = 0; i < sk_OPENSSL_STRING_num(cfg.osk); i++) { |
| 341 | ASN1_TYPE *atmp; | 341 | ASN1_TYPE *atmp; |
| @@ -351,8 +351,8 @@ asn1parse_main(int argc, char **argv) | |||
| 351 | tmpbuf += j; | 351 | tmpbuf += j; |
| 352 | tmplen -= j; | 352 | tmplen -= j; |
| 353 | atmp = at; | 353 | atmp = at; |
| 354 | ctmpbuf = tmpbuf; | 354 | p = tmpbuf; |
| 355 | at = d2i_ASN1_TYPE(NULL, &ctmpbuf, tmplen); | 355 | at = d2i_ASN1_TYPE(NULL, &p, tmplen); |
| 356 | ASN1_TYPE_free(atmp); | 356 | ASN1_TYPE_free(atmp); |
| 357 | if (!at) { | 357 | if (!at) { |
| 358 | BIO_printf(bio_err, "Error parsing structure\n"); | 358 | BIO_printf(bio_err, "Error parsing structure\n"); |
| @@ -371,7 +371,7 @@ asn1parse_main(int argc, char **argv) | |||
| 371 | tmpbuf = ASN1_STRING_get0_data(at->value.asn1_string); | 371 | tmpbuf = ASN1_STRING_get0_data(at->value.asn1_string); |
| 372 | tmplen = ASN1_STRING_length(at->value.asn1_string); | 372 | tmplen = ASN1_STRING_length(at->value.asn1_string); |
| 373 | } | 373 | } |
| 374 | str = (char *) tmpbuf; | 374 | str = tmpbuf; |
| 375 | num = tmplen; | 375 | num = tmplen; |
| 376 | } | 376 | } |
| 377 | if (cfg.offset >= num) { | 377 | if (cfg.offset >= num) { |
| @@ -390,8 +390,8 @@ asn1parse_main(int argc, char **argv) | |||
| 390 | goto end; | 390 | goto end; |
| 391 | } | 391 | } |
| 392 | } | 392 | } |
| 393 | if (!cfg.noout && !ASN1_parse_dump(out, | 393 | if (!cfg.noout && !ASN1_parse_dump(out, &str[cfg.offset], cfg.length, |
| 394 | (unsigned char *)&str[cfg.offset], cfg.length, cfg.indent, cfg.dump)) { | 394 | cfg.indent, cfg.dump)) { |
| 395 | ERR_print_errors(bio_err); | 395 | ERR_print_errors(bio_err); |
| 396 | goto end; | 396 | goto end; |
| 397 | } | 397 | } |
