diff options
author | deraadt <> | 2016-08-26 15:04:15 +0000 |
---|---|---|
committer | deraadt <> | 2016-08-26 15:04:15 +0000 |
commit | b4b57eb12b0e13327e453339091638ddfa9f4580 (patch) | |
tree | 6c069673db08d56bc684301ba78e0c66cd3fb78e | |
parent | 10d5180a267ee5020439470692936bb3f918f5f5 (diff) | |
download | openbsd-b4b57eb12b0e13327e453339091638ddfa9f4580.tar.gz openbsd-b4b57eb12b0e13327e453339091638ddfa9f4580.tar.bz2 openbsd-b4b57eb12b0e13327e453339091638ddfa9f4580.zip |
Repeated occurances of the idiom buf[5][BUFSIZ] -- ridiculous. Give each
buf a special name, recognize that most are PATH_MAX, and remove a few that
are not needed at all.
ok jsing beck
-rw-r--r-- | src/usr.bin/openssl/apps.c | 173 |
1 files changed, 87 insertions, 86 deletions
diff --git a/src/usr.bin/openssl/apps.c b/src/usr.bin/openssl/apps.c index 153504c503..2902fb7e99 100644 --- a/src/usr.bin/openssl/apps.c +++ b/src/usr.bin/openssl/apps.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: apps.c,v 1.37 2015/11/14 14:53:14 miod Exp $ */ | 1 | /* $OpenBSD: apps.c,v 1.38 2016/08/26 15:04:15 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -1269,8 +1269,6 @@ static IMPLEMENT_LHASH_COMP_FN(index_serial, OPENSSL_CSTRING) | |||
1269 | static IMPLEMENT_LHASH_HASH_FN(index_name, OPENSSL_CSTRING) | 1269 | static IMPLEMENT_LHASH_HASH_FN(index_name, OPENSSL_CSTRING) |
1270 | static IMPLEMENT_LHASH_COMP_FN(index_name, OPENSSL_CSTRING) | 1270 | static IMPLEMENT_LHASH_COMP_FN(index_name, OPENSSL_CSTRING) |
1271 | 1271 | ||
1272 | #define BUFLEN 256 | ||
1273 | |||
1274 | BIGNUM * | 1272 | BIGNUM * |
1275 | load_serial(char *serialfile, int create, ASN1_INTEGER **retai) | 1273 | load_serial(char *serialfile, int create, ASN1_INTEGER **retai) |
1276 | { | 1274 | { |
@@ -1297,7 +1295,7 @@ load_serial(char *serialfile, int create, ASN1_INTEGER **retai) | |||
1297 | BIO_printf(bio_err, "Out of memory\n"); | 1295 | BIO_printf(bio_err, "Out of memory\n"); |
1298 | } | 1296 | } |
1299 | } else { | 1297 | } else { |
1300 | if (!a2i_ASN1_INTEGER(in, ai, buf, 1024)) { | 1298 | if (!a2i_ASN1_INTEGER(in, ai, buf, sizeof buf)) { |
1301 | BIO_printf(bio_err, "unable to load number from %s\n", | 1299 | BIO_printf(bio_err, "unable to load number from %s\n", |
1302 | serialfile); | 1300 | serialfile); |
1303 | goto err; | 1301 | goto err; |
@@ -1327,26 +1325,17 @@ int | |||
1327 | save_serial(char *serialfile, char *suffix, BIGNUM *serial, | 1325 | save_serial(char *serialfile, char *suffix, BIGNUM *serial, |
1328 | ASN1_INTEGER **retai) | 1326 | ASN1_INTEGER **retai) |
1329 | { | 1327 | { |
1330 | char buf[1][BUFLEN]; | 1328 | char serialpath[PATH_MAX]; |
1331 | BIO *out = NULL; | 1329 | BIO *out = NULL; |
1332 | int ret = 0, n; | 1330 | int ret = 0, n; |
1333 | ASN1_INTEGER *ai = NULL; | 1331 | ASN1_INTEGER *ai = NULL; |
1334 | int j; | ||
1335 | 1332 | ||
1336 | if (suffix == NULL) | 1333 | if (suffix == NULL) |
1337 | j = strlen(serialfile); | 1334 | n = strlcpy(serialpath, serialfile, sizeof serialpath); |
1338 | else | 1335 | else |
1339 | j = strlen(serialfile) + strlen(suffix) + 1; | 1336 | n = snprintf(serialpath, sizeof serialpath, "%s.%s", |
1340 | if (j >= BUFLEN) { | ||
1341 | BIO_printf(bio_err, "file name too long\n"); | ||
1342 | goto err; | ||
1343 | } | ||
1344 | if (suffix == NULL) | ||
1345 | n = strlcpy(buf[0], serialfile, BUFLEN); | ||
1346 | else | ||
1347 | n = snprintf(buf[0], sizeof buf[0], "%s.%s", | ||
1348 | serialfile, suffix); | 1337 | serialfile, suffix); |
1349 | if (n == -1 || n >= sizeof(buf[0])) { | 1338 | if (n == -1 || n >= sizeof(serialpath)) { |
1350 | BIO_printf(bio_err, "serial too long\n"); | 1339 | BIO_printf(bio_err, "serial too long\n"); |
1351 | goto err; | 1340 | goto err; |
1352 | } | 1341 | } |
@@ -1355,7 +1344,7 @@ save_serial(char *serialfile, char *suffix, BIGNUM *serial, | |||
1355 | ERR_print_errors(bio_err); | 1344 | ERR_print_errors(bio_err); |
1356 | goto err; | 1345 | goto err; |
1357 | } | 1346 | } |
1358 | if (BIO_write_filename(out, buf[0]) <= 0) { | 1347 | if (BIO_write_filename(out, serialpath) <= 0) { |
1359 | perror(serialfile); | 1348 | perror(serialfile); |
1360 | goto err; | 1349 | goto err; |
1361 | } | 1350 | } |
@@ -1383,37 +1372,36 @@ err: | |||
1383 | int | 1372 | int |
1384 | rotate_serial(char *serialfile, char *new_suffix, char *old_suffix) | 1373 | rotate_serial(char *serialfile, char *new_suffix, char *old_suffix) |
1385 | { | 1374 | { |
1386 | char buf[5][BUFLEN]; | 1375 | char opath[PATH_MAX], npath[PATH_MAX]; |
1387 | int i, j; | ||
1388 | 1376 | ||
1389 | i = strlen(serialfile) + strlen(old_suffix); | 1377 | if (snprintf(npath, sizeof npath, "%s.%s", serialfile, |
1390 | j = strlen(serialfile) + strlen(new_suffix); | 1378 | new_suffix) >= sizeof npath) { |
1391 | if (i > j) | ||
1392 | j = i; | ||
1393 | if (j + 1 >= BUFLEN) { | ||
1394 | BIO_printf(bio_err, "file name too long\n"); | 1379 | BIO_printf(bio_err, "file name too long\n"); |
1395 | goto err; | 1380 | goto err; |
1396 | } | 1381 | } |
1397 | snprintf(buf[0], sizeof buf[0], "%s.%s", serialfile, new_suffix); | ||
1398 | snprintf(buf[1], sizeof buf[1], "%s.%s", serialfile, old_suffix); | ||
1399 | 1382 | ||
1383 | if (snprintf(opath, sizeof opath, "%s.%s", serialfile, | ||
1384 | old_suffix) >= sizeof opath) { | ||
1385 | BIO_printf(bio_err, "file name too long\n"); | ||
1386 | goto err; | ||
1387 | } | ||
1400 | 1388 | ||
1401 | if (rename(serialfile, buf[1]) < 0 && | 1389 | if (rename(serialfile, opath) < 0 && |
1402 | errno != ENOENT && errno != ENOTDIR) { | 1390 | errno != ENOENT && errno != ENOTDIR) { |
1403 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1391 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1404 | serialfile, buf[1]); | 1392 | serialfile, opath); |
1405 | perror("reason"); | 1393 | perror("reason"); |
1406 | goto err; | 1394 | goto err; |
1407 | } | 1395 | } |
1408 | 1396 | ||
1409 | 1397 | ||
1410 | if (rename(buf[0], serialfile) < 0) { | 1398 | if (rename(npath, serialfile) < 0) { |
1411 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1399 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1412 | buf[0], serialfile); | 1400 | npath, serialfile); |
1413 | perror("reason"); | 1401 | perror("reason"); |
1414 | if (rename(buf[1], serialfile) < 0) { | 1402 | if (rename(opath, serialfile) < 0) { |
1415 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1403 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1416 | buf[1], serialfile); | 1404 | opath, serialfile); |
1417 | perror("reason"); | 1405 | perror("reason"); |
1418 | } | 1406 | } |
1419 | goto err; | 1407 | goto err; |
@@ -1459,7 +1447,7 @@ load_index(char *dbfile, DB_ATTR *db_attr) | |||
1459 | TXT_DB *tmpdb = NULL; | 1447 | TXT_DB *tmpdb = NULL; |
1460 | BIO *in = BIO_new(BIO_s_file()); | 1448 | BIO *in = BIO_new(BIO_s_file()); |
1461 | CONF *dbattr_conf = NULL; | 1449 | CONF *dbattr_conf = NULL; |
1462 | char buf[1][BUFLEN]; | 1450 | char attrpath[PATH_MAX]; |
1463 | long errorline = -1; | 1451 | long errorline = -1; |
1464 | 1452 | ||
1465 | if (in == NULL) { | 1453 | if (in == NULL) { |
@@ -1474,13 +1462,18 @@ load_index(char *dbfile, DB_ATTR *db_attr) | |||
1474 | if ((tmpdb = TXT_DB_read(in, DB_NUMBER)) == NULL) | 1462 | if ((tmpdb = TXT_DB_read(in, DB_NUMBER)) == NULL) |
1475 | goto err; | 1463 | goto err; |
1476 | 1464 | ||
1477 | snprintf(buf[0], sizeof buf[0], "%s.attr", dbfile); | 1465 | if (snprintf(attrpath, sizeof attrpath, "%s.attr", dbfile) |
1466 | >= sizeof attrpath) { | ||
1467 | BIO_printf(bio_err, "attr filename too long\n"); | ||
1468 | goto err; | ||
1469 | } | ||
1470 | |||
1478 | dbattr_conf = NCONF_new(NULL); | 1471 | dbattr_conf = NCONF_new(NULL); |
1479 | if (NCONF_load(dbattr_conf, buf[0], &errorline) <= 0) { | 1472 | if (NCONF_load(dbattr_conf, attrpath, &errorline) <= 0) { |
1480 | if (errorline > 0) { | 1473 | if (errorline > 0) { |
1481 | BIO_printf(bio_err, | 1474 | BIO_printf(bio_err, |
1482 | "error on line %ld of db attribute file '%s'\n", | 1475 | "error on line %ld of db attribute file '%s'\n", |
1483 | errorline, buf[0]); | 1476 | errorline, attrpath); |
1484 | goto err; | 1477 | goto err; |
1485 | } else { | 1478 | } else { |
1486 | NCONF_free(dbattr_conf); | 1479 | NCONF_free(dbattr_conf); |
@@ -1537,9 +1530,9 @@ index_index(CA_DB *db) | |||
1537 | } | 1530 | } |
1538 | 1531 | ||
1539 | int | 1532 | int |
1540 | save_index(const char *dbfile, const char *suffix, CA_DB *db) | 1533 | save_index(const char *file, const char *suffix, CA_DB *db) |
1541 | { | 1534 | { |
1542 | char buf[3][BUFLEN]; | 1535 | char attrpath[PATH_MAX], dbfile[PATH_MAX]; |
1543 | BIO *out = BIO_new(BIO_s_file()); | 1536 | BIO *out = BIO_new(BIO_s_file()); |
1544 | int j; | 1537 | int j; |
1545 | 1538 | ||
@@ -1547,17 +1540,18 @@ save_index(const char *dbfile, const char *suffix, CA_DB *db) | |||
1547 | ERR_print_errors(bio_err); | 1540 | ERR_print_errors(bio_err); |
1548 | goto err; | 1541 | goto err; |
1549 | } | 1542 | } |
1550 | j = strlen(dbfile) + strlen(suffix); | 1543 | if (snprintf(attrpath, sizeof attrpath, "%s.attr.%s", |
1551 | if (j + 6 >= BUFLEN) { | 1544 | file, suffix) >= sizeof attrpath) { |
1545 | BIO_printf(bio_err, "file name too long\n"); | ||
1546 | goto err; | ||
1547 | } | ||
1548 | if (snprintf(dbfile, sizeof dbfile, "%s.%s", | ||
1549 | file, suffix) >= sizeof dbfile) { | ||
1552 | BIO_printf(bio_err, "file name too long\n"); | 1550 | BIO_printf(bio_err, "file name too long\n"); |
1553 | goto err; | 1551 | goto err; |
1554 | } | 1552 | } |
1555 | snprintf(buf[2], sizeof buf[2], "%s.attr", dbfile); | ||
1556 | snprintf(buf[1], sizeof buf[1], "%s.attr.%s", dbfile, suffix); | ||
1557 | snprintf(buf[0], sizeof buf[0], "%s.%s", dbfile, suffix); | ||
1558 | |||
1559 | 1553 | ||
1560 | if (BIO_write_filename(out, buf[0]) <= 0) { | 1554 | if (BIO_write_filename(out, dbfile) <= 0) { |
1561 | perror(dbfile); | 1555 | perror(dbfile); |
1562 | BIO_printf(bio_err, "unable to open '%s'\n", dbfile); | 1556 | BIO_printf(bio_err, "unable to open '%s'\n", dbfile); |
1563 | goto err; | 1557 | goto err; |
@@ -1570,10 +1564,9 @@ save_index(const char *dbfile, const char *suffix, CA_DB *db) | |||
1570 | 1564 | ||
1571 | out = BIO_new(BIO_s_file()); | 1565 | out = BIO_new(BIO_s_file()); |
1572 | 1566 | ||
1573 | 1567 | if (BIO_write_filename(out, attrpath) <= 0) { | |
1574 | if (BIO_write_filename(out, buf[1]) <= 0) { | 1568 | perror(attrpath); |
1575 | perror(buf[2]); | 1569 | BIO_printf(bio_err, "unable to open '%s'\n", attrpath); |
1576 | BIO_printf(bio_err, "unable to open '%s'\n", buf[2]); | ||
1577 | goto err; | 1570 | goto err; |
1578 | } | 1571 | } |
1579 | BIO_printf(out, "unique_subject = %s\n", | 1572 | BIO_printf(out, "unique_subject = %s\n", |
@@ -1589,80 +1582,88 @@ err: | |||
1589 | int | 1582 | int |
1590 | rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix) | 1583 | rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix) |
1591 | { | 1584 | { |
1592 | char buf[5][BUFLEN]; | 1585 | char attrpath[PATH_MAX], nattrpath[PATH_MAX], oattrpath[PATH_MAX]; |
1593 | int i, j; | 1586 | char dbpath[PATH_MAX], odbpath[PATH_MAX]; |
1594 | 1587 | ||
1595 | i = strlen(dbfile) + strlen(old_suffix); | 1588 | if (snprintf(attrpath, sizeof attrpath, "%s.attr", |
1596 | j = strlen(dbfile) + strlen(new_suffix); | 1589 | dbfile) >= sizeof attrpath) { |
1597 | if (i > j) | 1590 | BIO_printf(bio_err, "file name too long\n"); |
1598 | j = i; | 1591 | goto err; |
1599 | if (j + 6 >= BUFLEN) { | 1592 | } |
1593 | if (snprintf(nattrpath, sizeof nattrpath, "%s.attr.%s", | ||
1594 | dbfile, new_suffix) >= sizeof nattrpath) { | ||
1595 | BIO_printf(bio_err, "file name too long\n"); | ||
1596 | goto err; | ||
1597 | } | ||
1598 | if (snprintf(oattrpath, sizeof oattrpath, "%s.attr.%s", | ||
1599 | dbfile, old_suffix) >= sizeof oattrpath) { | ||
1600 | BIO_printf(bio_err, "file name too long\n"); | ||
1601 | goto err; | ||
1602 | } | ||
1603 | if (snprintf(dbpath, sizeof dbpath, "%s.%s", | ||
1604 | dbfile, new_suffix) >= sizeof dbpath) { | ||
1605 | BIO_printf(bio_err, "file name too long\n"); | ||
1606 | goto err; | ||
1607 | } | ||
1608 | if (snprintf(odbpath, sizeof odbpath, "%s.%s", | ||
1609 | dbfile, old_suffix) >= sizeof odbpath) { | ||
1600 | BIO_printf(bio_err, "file name too long\n"); | 1610 | BIO_printf(bio_err, "file name too long\n"); |
1601 | goto err; | 1611 | goto err; |
1602 | } | 1612 | } |
1603 | snprintf(buf[4], sizeof buf[4], "%s.attr", dbfile); | ||
1604 | snprintf(buf[2], sizeof buf[2], "%s.attr.%s", dbfile, new_suffix); | ||
1605 | snprintf(buf[0], sizeof buf[0], "%s.%s", dbfile, new_suffix); | ||
1606 | snprintf(buf[1], sizeof buf[1], "%s.%s", dbfile, old_suffix); | ||
1607 | snprintf(buf[3], sizeof buf[3], "%s.attr.%s", dbfile, old_suffix); | ||
1608 | |||
1609 | 1613 | ||
1610 | if (rename(dbfile, buf[1]) < 0 && errno != ENOENT && errno != ENOTDIR) { | 1614 | if (rename(dbfile, odbpath) < 0 && errno != ENOENT && errno != ENOTDIR) { |
1611 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1615 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1612 | dbfile, buf[1]); | 1616 | dbfile, odbpath); |
1613 | perror("reason"); | 1617 | perror("reason"); |
1614 | goto err; | 1618 | goto err; |
1615 | } | 1619 | } |
1616 | 1620 | ||
1617 | 1621 | if (rename(dbpath, dbfile) < 0) { | |
1618 | if (rename(buf[0], dbfile) < 0) { | ||
1619 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1622 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1620 | buf[0], dbfile); | 1623 | dbpath, dbfile); |
1621 | perror("reason"); | 1624 | perror("reason"); |
1622 | if (rename(buf[1], dbfile) < 0) { | 1625 | if (rename(odbpath, dbfile) < 0) { |
1623 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1626 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1624 | buf[1], dbfile); | 1627 | odbpath, dbfile); |
1625 | perror("reason"); | 1628 | perror("reason"); |
1626 | } | 1629 | } |
1627 | goto err; | 1630 | goto err; |
1628 | } | 1631 | } |
1629 | 1632 | ||
1630 | 1633 | if (rename(attrpath, oattrpath) < 0 && errno != ENOENT && errno != ENOTDIR) { | |
1631 | if (rename(buf[4], buf[3]) < 0 && errno != ENOENT && errno != ENOTDIR) { | ||
1632 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1634 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1633 | buf[4], buf[3]); | 1635 | attrpath, oattrpath); |
1634 | perror("reason"); | 1636 | perror("reason"); |
1635 | if (rename(dbfile, buf[0]) < 0) { | 1637 | if (rename(dbfile, dbpath) < 0) { |
1636 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1638 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1637 | dbfile, buf[0]); | 1639 | dbfile, dbpath); |
1638 | perror("reason"); | 1640 | perror("reason"); |
1639 | } | 1641 | } |
1640 | if (rename(buf[1], dbfile) < 0) { | 1642 | if (rename(odbpath, dbfile) < 0) { |
1641 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1643 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1642 | buf[1], dbfile); | 1644 | odbpath, dbfile); |
1643 | perror("reason"); | 1645 | perror("reason"); |
1644 | } | 1646 | } |
1645 | goto err; | 1647 | goto err; |
1646 | } | 1648 | } |
1647 | 1649 | ||
1648 | 1650 | if (rename(nattrpath, attrpath) < 0) { | |
1649 | if (rename(buf[2], buf[4]) < 0) { | ||
1650 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1651 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1651 | buf[2], buf[4]); | 1652 | nattrpath, attrpath); |
1652 | perror("reason"); | 1653 | perror("reason"); |
1653 | if (rename(buf[3], buf[4]) < 0) { | 1654 | if (rename(oattrpath, attrpath) < 0) { |
1654 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1655 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1655 | buf[3], buf[4]); | 1656 | oattrpath, attrpath); |
1656 | perror("reason"); | 1657 | perror("reason"); |
1657 | } | 1658 | } |
1658 | if (rename(dbfile, buf[0]) < 0) { | 1659 | if (rename(dbfile, dbpath) < 0) { |
1659 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1660 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1660 | dbfile, buf[0]); | 1661 | dbfile, dbpath); |
1661 | perror("reason"); | 1662 | perror("reason"); |
1662 | } | 1663 | } |
1663 | if (rename(buf[1], dbfile) < 0) { | 1664 | if (rename(odbpath, dbfile) < 0) { |
1664 | BIO_printf(bio_err, "unable to rename %s to %s\n", | 1665 | BIO_printf(bio_err, "unable to rename %s to %s\n", |
1665 | buf[1], dbfile); | 1666 | odbpath, dbfile); |
1666 | perror("reason"); | 1667 | perror("reason"); |
1667 | } | 1668 | } |
1668 | goto err; | 1669 | goto err; |