diff options
author | tb <> | 2020-11-25 21:17:52 +0000 |
---|---|---|
committer | tb <> | 2020-11-25 21:17:52 +0000 |
commit | e184d9b4d57f92ba4003625ca5e4bf386ad6843f (patch) | |
tree | 6658abd0ba870d77cbb0aa60a0607146508d9159 /src/lib | |
parent | 4594ab4487e73070cff05c330cce9ed796246510 (diff) | |
download | openbsd-e184d9b4d57f92ba4003625ca5e4bf386ad6843f.tar.gz openbsd-e184d9b4d57f92ba4003625ca5e4bf386ad6843f.tar.bz2 openbsd-e184d9b4d57f92ba4003625ca5e4bf386ad6843f.zip |
Avoid undefined behavior due to memcpy(NULL, NULL, 0)
This happens if name->der_len == 0. Since we already have a length
check, we can malloc and memcpy inside the conditional. This also
makes the code easier to read.
agreement from millert
ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/x509/x509_constraints.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lib/libcrypto/x509/x509_constraints.c b/src/lib/libcrypto/x509/x509_constraints.c index dc91c00345..67cbaa6313 100644 --- a/src/lib/libcrypto/x509/x509_constraints.c +++ b/src/lib/libcrypto/x509/x509_constraints.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_constraints.c,v 1.11 2020/11/18 17:00:59 tb Exp $ */ | 1 | /* $OpenBSD: x509_constraints.c,v 1.12 2020/11/25 21:17:52 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2020 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2020 Bob Beck <beck@openbsd.org> |
4 | * | 4 | * |
@@ -69,9 +69,11 @@ x509_constraints_name_dup(struct x509_constraints_name *name) | |||
69 | new->type = name->type; | 69 | new->type = name->type; |
70 | new->af = name->af; | 70 | new->af = name->af; |
71 | new->der_len = name->der_len; | 71 | new->der_len = name->der_len; |
72 | if (name->der_len > 0 && (new->der = malloc(name->der_len)) == NULL) | 72 | if (name->der_len > 0) { |
73 | goto err; | 73 | if ((new->der = malloc(name->der_len)) == NULL) |
74 | memcpy(new->der, name->der, name->der_len); | 74 | goto err; |
75 | memcpy(new->der, name->der, name->der_len); | ||
76 | } | ||
75 | if (name->name != NULL && (new->name = strdup(name->name)) == NULL) | 77 | if (name->name != NULL && (new->name = strdup(name->name)) == NULL) |
76 | goto err; | 78 | goto err; |
77 | if (name->local != NULL && (new->local = strdup(name->local)) == NULL) | 79 | if (name->local != NULL && (new->local = strdup(name->local)) == NULL) |