From: Joseph Sutton Date: Wed, 8 Nov 2023 03:18:54 +0000 (+1300) Subject: librpc:ndr: Check return values of talloc functions X-Git-Tag: talloc-2.4.2~691 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ef0109d2cd723d92b01888ea257dc3b8d1d9ac86;p=thirdparty%2Fsamba.git librpc:ndr: Check return values of talloc functions Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- diff --git a/librpc/ndr/ndr_string.c b/librpc/ndr/ndr_string.c index c340e4d2459..277304315b5 100644 --- a/librpc/ndr/ndr_string.c +++ b/librpc/ndr/ndr_string.c @@ -293,9 +293,17 @@ _PUBLIC_ enum ndr_err_code ndr_push_string(struct ndr_push *ndr, ndr_flags_type if (s_len == 0) { d_len = 0; dest = (uint8_t *)talloc_strdup(ndr, ""); + if (dest == NULL) { + return ndr_push_error(ndr, NDR_ERR_ALLOC, + "Failed to talloc_strdup() in ndr_string_push()"); + } } else if (!do_convert) { d_len = s_len; dest = (uint8_t *)talloc_strndup(ndr, s, s_len); + if (dest == NULL) { + return ndr_push_error(ndr, NDR_ERR_ALLOC, + "Failed to talloc_strndup() in ndr_string_push()"); + } } else if (!convert_string_talloc(ndr, CH_UNIX, chset, s, s_len, &dest, &d_len)) { @@ -745,6 +753,10 @@ _PUBLIC_ enum ndr_err_code ndr_pull_charset(struct ndr_pull *ndr, ndr_flags_type if (length == 0) { *var = talloc_strdup(ndr->current_mem_ctx, ""); + if (*var == NULL) { + return ndr_pull_error(ndr, NDR_ERR_ALLOC, + "Failed to talloc_strdup() in ndr_pull_charset()"); + } return NDR_ERR_SUCCESS; } @@ -777,6 +789,10 @@ _PUBLIC_ enum ndr_err_code ndr_pull_charset_to_null(struct ndr_pull *ndr, ndr_fl if (length == 0) { *var = talloc_strdup(ndr->current_mem_ctx, ""); + if (*var == NULL) { + return ndr_pull_error(ndr, NDR_ERR_ALLOC, + "Failed to talloc_strdup() in ndr_pull_charset_to_null()"); + } return NDR_ERR_SUCCESS; }