summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorinoguchi <>2021-08-28 05:14:30 +0000
committerinoguchi <>2021-08-28 05:14:30 +0000
commitc317acb2df2cd1b6b91311917823f4ccb4c7c3df (patch)
tree422179df76f579280cf232271133753dcfd37413 /src
parent3ba7efbed9520ab7baa261ea2ba20a724f9b3654 (diff)
downloadopenbsd-c317acb2df2cd1b6b91311917823f4ccb4c7c3df.tar.gz
openbsd-c317acb2df2cd1b6b91311917823f4ccb4c7c3df.tar.bz2
openbsd-c317acb2df2cd1b6b91311917823f4ccb4c7c3df.zip
Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c
suggested from tb@ for do_updatedb(), and applied the same for do_body() and do_revoke().
Diffstat (limited to 'src')
-rw-r--r--src/usr.bin/openssl/ca.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/usr.bin/openssl/ca.c b/src/usr.bin/openssl/ca.c
index b04a93b065..f7e3a73007 100644
--- a/src/usr.bin/openssl/ca.c
+++ b/src/usr.bin/openssl/ca.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ca.c,v 1.39 2021/08/28 04:02:20 inoguchi Exp $ */ 1/* $OpenBSD: ca.c,v 1.40 2021/08/28 05:14:30 inoguchi 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 *
@@ -2247,15 +2247,12 @@ do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, const EVP_MD *dgst,
2247 row[DB_type] = malloc(2); 2247 row[DB_type] = malloc(2);
2248 2248
2249 tm = X509_get_notAfter(ret); 2249 tm = X509_get_notAfter(ret);
2250 row[DB_exp_date] = malloc(tm->length + 1); 2250 row[DB_exp_date] = strndup(tm->data, tm->length);
2251 if (row[DB_type] == NULL || row[DB_exp_date] == NULL) { 2251 if (row[DB_type] == NULL || row[DB_exp_date] == NULL) {
2252 BIO_printf(bio_err, "Memory allocation failure\n"); 2252 BIO_printf(bio_err, "Memory allocation failure\n");
2253 goto err; 2253 goto err;
2254 } 2254 }
2255 2255
2256 memcpy(row[DB_exp_date], tm->data, tm->length);
2257 row[DB_exp_date][tm->length] = '\0';
2258
2259 row[DB_rev_date] = NULL; 2256 row[DB_rev_date] = NULL;
2260 2257
2261 /* row[DB_serial] done already */ 2258 /* row[DB_serial] done already */
@@ -2507,13 +2504,11 @@ do_revoke(X509 *x509, CA_DB *db, int type, char *value)
2507 row[DB_type] = malloc(2); 2504 row[DB_type] = malloc(2);
2508 2505
2509 tm = X509_get_notAfter(x509); 2506 tm = X509_get_notAfter(x509);
2510 row[DB_exp_date] = malloc(tm->length + 1); 2507 row[DB_exp_date] = strndup(tm->data, tm->length);
2511 if (row[DB_type] == NULL || row[DB_exp_date] == NULL) { 2508 if (row[DB_type] == NULL || row[DB_exp_date] == NULL) {
2512 BIO_printf(bio_err, "Memory allocation failure\n"); 2509 BIO_printf(bio_err, "Memory allocation failure\n");
2513 goto err; 2510 goto err;
2514 } 2511 }
2515 memcpy(row[DB_exp_date], tm->data, tm->length);
2516 row[DB_exp_date][tm->length] = '\0';
2517 2512
2518 row[DB_rev_date] = NULL; 2513 row[DB_rev_date] = NULL;
2519 2514
@@ -2673,13 +2668,11 @@ do_updatedb(CA_DB *db)
2673 cnt = -1; 2668 cnt = -1;
2674 goto err; 2669 goto err;
2675 } 2670 }
2676 a_tm_s = malloc(a_tm->length + 1); 2671 a_tm_s = strndup(a_tm->data, a_tm->length);
2677 if (a_tm_s == NULL) { 2672 if (a_tm_s == NULL) {
2678 cnt = -1; 2673 cnt = -1;
2679 goto err; 2674 goto err;
2680 } 2675 }
2681 memcpy(a_tm_s, a_tm->data, a_tm->length);
2682 a_tm_s[a_tm->length] = '\0';
2683 2676
2684 if (strncmp(a_tm_s, "49", 2) <= 0) 2677 if (strncmp(a_tm_s, "49", 2) <= 0)
2685 a_y2k = 1; 2678 a_y2k = 1;