=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/openssl/asn1pars.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- src/usr.bin/openssl/asn1pars.c 2022/11/11 17:07:38 1.12 +++ src/usr.bin/openssl/asn1pars.c 2023/03/06 14:32:05 1.13 @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1pars.c,v 1.12 2022/11/11 17:07:38 joshua Exp $ */ +/* $OpenBSD: asn1pars.c,v 1.13 2023/03/06 14:32:05 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -86,14 +86,14 @@ int offset; char *oidfile; STACK_OF(OPENSSL_STRING) *osk; -} asn1pars_config; +} cfg; static int asn1pars_opt_dlimit(char *arg) { const char *errstr; - asn1pars_config.dump = strtonum(arg, 1, INT_MAX, &errstr); + cfg.dump = strtonum(arg, 1, INT_MAX, &errstr); if (errstr) { fprintf(stderr, "-dlimit must be from 1 to INT_MAX: %s\n", errstr); @@ -107,7 +107,7 @@ { const char *errstr; - asn1pars_config.length = strtonum(arg, 1, UINT_MAX, &errstr); + cfg.length = strtonum(arg, 1, UINT_MAX, &errstr); if (errstr) { fprintf(stderr, "-length must be from 1 to UINT_MAX: %s\n", errstr); @@ -119,7 +119,7 @@ static int asn1pars_opt_strparse(char *arg) { - if (sk_OPENSSL_STRING_push(asn1pars_config.osk, arg) == 0) { + if (sk_OPENSSL_STRING_push(cfg.osk, arg) == 0) { fprintf(stderr, "-strparse cannot add argument\n"); return (-1); } @@ -132,7 +132,7 @@ .desc = "Dump unknown data in hex form", .type = OPTION_VALUE, .value = -1, - .opt.value = &asn1pars_config.dump, + .opt.value = &cfg.dump, }, { .name = "dlimit", @@ -146,34 +146,34 @@ .argname = "file", .desc = "File to generate ASN.1 structure from", .type = OPTION_ARG, - .opt.arg = &asn1pars_config.genconf, + .opt.arg = &cfg.genconf, }, { .name = "genstr", .argname = "string", .desc = "String to generate ASN.1 structure from", .type = OPTION_ARG, - .opt.arg = &asn1pars_config.genstr, + .opt.arg = &cfg.genstr, }, { .name = "i", .desc = "Indent output according to depth of structures", .type = OPTION_FLAG, - .opt.flag = &asn1pars_config.indent, + .opt.flag = &cfg.indent, }, { .name = "in", .argname = "file", .desc = "The input file (default stdin)", .type = OPTION_ARG, - .opt.arg = &asn1pars_config.infile, + .opt.arg = &cfg.infile, }, { .name = "inform", .argname = "fmt", .desc = "Input format (DER, TXT or PEM (default))", .type = OPTION_ARG_FORMAT, - .opt.value = &asn1pars_config.informat, + .opt.value = &cfg.informat, }, { .name = "length", @@ -186,28 +186,28 @@ .name = "noout", .desc = "Do not produce any output", .type = OPTION_FLAG, - .opt.flag = &asn1pars_config.noout, + .opt.flag = &cfg.noout, }, { .name = "offset", .argname = "num", .desc = "Offset to begin parsing", .type = OPTION_ARG_INT, - .opt.value = &asn1pars_config.offset, + .opt.value = &cfg.offset, }, { .name = "oid", .argname = "file", .desc = "File containing additional object identifiers (OIDs)", .type = OPTION_ARG, - .opt.arg = &asn1pars_config.oidfile, + .opt.arg = &cfg.oidfile, }, { .name = "out", .argname = "file", .desc = "Output file in DER format", .type = OPTION_ARG, - .opt.arg = &asn1pars_config.derfile, + .opt.arg = &cfg.derfile, }, { .name = "strparse", @@ -252,10 +252,10 @@ exit(1); } - memset(&asn1pars_config, 0, sizeof(asn1pars_config)); + memset(&cfg, 0, sizeof(cfg)); - asn1pars_config.informat = FORMAT_PEM; - if ((asn1pars_config.osk = sk_OPENSSL_STRING_new_null()) == NULL) { + cfg.informat = FORMAT_PEM; + if ((cfg.osk = sk_OPENSSL_STRING_new_null()) == NULL) { BIO_printf(bio_err, "Memory allocation failure\n"); goto end; } @@ -273,28 +273,28 @@ } BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); - if (asn1pars_config.oidfile != NULL) { - if (BIO_read_filename(in, asn1pars_config.oidfile) <= 0) { + if (cfg.oidfile != NULL) { + if (BIO_read_filename(in, cfg.oidfile) <= 0) { BIO_printf(bio_err, "problems opening %s\n", - asn1pars_config.oidfile); + cfg.oidfile); ERR_print_errors(bio_err); goto end; } OBJ_create_objects(in); } - if (asn1pars_config.infile == NULL) + if (cfg.infile == NULL) BIO_set_fp(in, stdin, BIO_NOCLOSE); else { - if (BIO_read_filename(in, asn1pars_config.infile) <= 0) { - perror(asn1pars_config.infile); + if (BIO_read_filename(in, cfg.infile) <= 0) { + perror(cfg.infile); goto end; } } - if (asn1pars_config.derfile) { - if (!(derout = BIO_new_file(asn1pars_config.derfile, "wb"))) { + if (cfg.derfile) { + if (!(derout = BIO_new_file(cfg.derfile, "wb"))) { BIO_printf(bio_err, "problems opening %s\n", - asn1pars_config.derfile); + cfg.derfile); ERR_print_errors(bio_err); goto end; } @@ -304,16 +304,16 @@ if (!BUF_MEM_grow(buf, BUFSIZ * 8)) goto end; /* Pre-allocate :-) */ - if (asn1pars_config.genstr || asn1pars_config.genconf) { - num = do_generate(bio_err, asn1pars_config.genstr, - asn1pars_config.genconf, buf); + if (cfg.genstr || cfg.genconf) { + num = do_generate(bio_err, cfg.genstr, + cfg.genconf, buf); if (num < 0) { ERR_print_errors(bio_err); goto end; } } else { - if (asn1pars_config.informat == FORMAT_PEM) { + if (cfg.informat == FORMAT_PEM) { BIO *tmp; if ((b64 = BIO_new(BIO_f_base64())) == NULL) @@ -337,20 +337,20 @@ /* If any structs to parse go through in sequence */ - if (sk_OPENSSL_STRING_num(asn1pars_config.osk)) { + if (sk_OPENSSL_STRING_num(cfg.osk)) { tmpbuf = (unsigned char *) str; tmplen = num; - for (i = 0; i < sk_OPENSSL_STRING_num(asn1pars_config.osk); + for (i = 0; i < sk_OPENSSL_STRING_num(cfg.osk); i++) { ASN1_TYPE *atmp; int typ; j = strtonum( - sk_OPENSSL_STRING_value(asn1pars_config.osk, i), + sk_OPENSSL_STRING_value(cfg.osk, i), 1, INT_MAX, &errstr); if (errstr) { BIO_printf(bio_err, "'%s' is an invalid number: %s\n", - sk_OPENSSL_STRING_value(asn1pars_config.osk, + sk_OPENSSL_STRING_value(cfg.osk, i), errstr); continue; } @@ -380,28 +380,28 @@ str = (char *) tmpbuf; num = tmplen; } - if (asn1pars_config.offset >= num) { + if (cfg.offset >= num) { BIO_printf(bio_err, "Error: offset too large\n"); goto end; } - num -= asn1pars_config.offset; + num -= cfg.offset; - if ((asn1pars_config.length == 0) || - ((long)asn1pars_config.length > num)) - asn1pars_config.length = (unsigned int) num; + if ((cfg.length == 0) || + ((long)cfg.length > num)) + cfg.length = (unsigned int) num; if (derout) { - if (BIO_write(derout, str + asn1pars_config.offset, - asn1pars_config.length) != (int)asn1pars_config.length) { + if (BIO_write(derout, str + cfg.offset, + cfg.length) != (int)cfg.length) { BIO_printf(bio_err, "Error writing output\n"); ERR_print_errors(bio_err); goto end; } } - if (!asn1pars_config.noout && + if (!cfg.noout && !ASN1_parse_dump(out, - (unsigned char *)&(str[asn1pars_config.offset]), - asn1pars_config.length, asn1pars_config.indent, - asn1pars_config.dump)) { + (unsigned char *)&(str[cfg.offset]), + cfg.length, cfg.indent, + cfg.dump)) { ERR_print_errors(bio_err); goto end; } @@ -415,7 +415,7 @@ ERR_print_errors(bio_err); BUF_MEM_free(buf); ASN1_TYPE_free(at); - sk_OPENSSL_STRING_free(asn1pars_config.osk); + sk_OPENSSL_STRING_free(cfg.osk); OBJ_cleanup(); return (ret);