From 03a50d8f7d872b6ef701d1207061c88b73d171bb Mon Sep 17 00:00:00 2001 From: Joseph Sutton Date: Tue, 2 Aug 2022 14:35:33 +1200 Subject: [PATCH] lib:util: Check memset_s() error code in talloc_keep_secret_destructor() Panic if memset_s() fails. Signed-off-by: Joseph Sutton Reviewed-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- lib/util/talloc_keep_secret.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/util/talloc_keep_secret.c b/lib/util/talloc_keep_secret.c index 70d449b5f12..21048659e5d 100644 --- a/lib/util/talloc_keep_secret.c +++ b/lib/util/talloc_keep_secret.c @@ -22,13 +22,26 @@ static int talloc_keep_secret_destructor(void *ptr) { + int ret; size_t size = talloc_get_size(ptr); if (unlikely(size == 0)) { return 0; } - memset_s(ptr, size, 0, size); + ret = memset_s(ptr, size, 0, size); + if (unlikely(ret != 0)) { + char *msg = NULL; + int ret2; + ret2 = asprintf(&msg, + "talloc_keep_secret_destructor: memset_s() failed: %s", + strerror(ret)); + if (ret2 != -1) { + smb_panic(msg); + } else { + smb_panic("talloc_keep_secret_destructor: memset_s() failed"); + } + } return 0; }