From cfa724cf6aec2c8b01b7611b510bc617bea7af64 Mon Sep 17 00:00:00 2001 From: tb <> Date: Sat, 24 May 2025 19:45:34 +0000 Subject: Create bm->buf from the start to avoid arithmetic on NULL This is a different way of avoiding the pointer arithmetic on NULL and avoids test breakage in pyca/cryptography. This is also a gross hack that penalizes existing callers of BIO_s_mem(), but this is rarely called in a hot loop and if so that will most likely be a test. ok kenjiro joshua jsing --- src/lib/libcrypto/bio/bss_mem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c index 0936ab4e83..f977a123a7 100644 --- a/src/lib/libcrypto/bio/bss_mem.c +++ b/src/lib/libcrypto/bio/bss_mem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bss_mem.c,v 1.25 2025/05/24 19:43:09 tb Exp $ */ +/* $OpenBSD: bss_mem.c,v 1.26 2025/05/24 19:45:34 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -162,6 +162,12 @@ mem_new(BIO *bio) free(bm); return 0; } + if (BUF_MEM_grow_clean(bm->buf, 64) != 64) { + BUF_MEM_free(bm->buf); + free(bm); + return 0; + } + bm->buf->length = 0; bio->shutdown = 1; bio->init = 1; -- cgit v1.2.3-55-g6feb