summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2021-10-31 06:48:54 +0000
committerjsing <>2021-10-31 06:48:54 +0000
commitbd06f1e8ae5fff9f6ae109217894e7f61176e903 (patch)
tree670b281eab33c66e6607a6118b3d184939e5076a
parent1507ec383c4225e409a40fc53eb43aec39bd4b66 (diff)
downloadopenbsd-bd06f1e8ae5fff9f6ae109217894e7f61176e903.tar.gz
openbsd-bd06f1e8ae5fff9f6ae109217894e7f61176e903.tar.bz2
openbsd-bd06f1e8ae5fff9f6ae109217894e7f61176e903.zip
Add explicit CBS_contains_zero_byte() check in CBS_strdup().
If the CBS data contains a zero byte, then CBS_strdup() is only going to return part of the data - add an explicit CBS_contains_zero_byte() and treat such data as an error case. ok tb@
-rw-r--r--src/lib/libssl/bs_cbs.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/lib/libssl/bs_cbs.c b/src/lib/libssl/bs_cbs.c
index 8d55871592..ab76b78927 100644
--- a/src/lib/libssl/bs_cbs.c
+++ b/src/lib/libssl/bs_cbs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bs_cbs.c,v 1.20 2021/05/16 10:58:27 jsing Exp $ */ 1/* $OpenBSD: bs_cbs.c,v 1.21 2021/10/31 06:48:54 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -95,6 +95,11 @@ int
95CBS_strdup(const CBS *cbs, char **out_ptr) 95CBS_strdup(const CBS *cbs, char **out_ptr)
96{ 96{
97 free(*out_ptr); 97 free(*out_ptr);
98 *out_ptr = NULL;
99
100 if (CBS_contains_zero_byte(cbs))
101 return 0;
102
98 *out_ptr = strndup((const char *)cbs->data, cbs->len); 103 *out_ptr = strndup((const char *)cbs->data, cbs->len);
99 return (*out_ptr != NULL); 104 return (*out_ptr != NULL);
100} 105}