From: Andrew Bartlett Date: Sun, 5 Nov 2023 21:18:47 +0000 (+1300) Subject: librpc/ndr: Remove confusing case where returned string pointer "as" could be NULL X-Git-Tag: talloc-2.4.2~781 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2b4a17f54fee552717068377dfc15f9999474fde;p=thirdparty%2Fsamba.git librpc/ndr: Remove confusing case where returned string pointer "as" could be NULL The failure to talloc_strdup("") is just an error and all other cases set the string or given an error. Signed-off-by: Andrew Bartlett Reviewed-by: Reviewed-by: Joseph Sutton --- diff --git a/librpc/ndr/ndr_string.c b/librpc/ndr/ndr_string.c index d0b64dc6fd9..988243abb0b 100644 --- a/librpc/ndr/ndr_string.c +++ b/librpc/ndr/ndr_string.c @@ -157,6 +157,10 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, ndr_flags_type if (conv_src_len == 0) { as = talloc_strdup(ndr->current_mem_ctx, ""); converted_size = 0; + if (!as) { + return ndr_pull_error(ndr, NDR_ERR_ALLOC, + "Failed to talloc_strndup() in zero-length ndr_string_pull()"); + } } else { if (!do_convert) { as = talloc_strndup(ndr->current_mem_ctx, @@ -180,11 +184,11 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, ndr_flags_type /* this is a way of detecting if a string is sent with the wrong termination */ if (ndr->flags & LIBNDR_FLAG_STR_NOTERM) { - if (as && converted_size > 0 && as[converted_size-1] == '\0') { + if (converted_size > 0 && as[converted_size-1] == '\0') { DEBUG(6,("short string '%s', sent with NULL termination despite NOTERM flag in IDL\n", as)); } } else { - if (as && converted_size > 0 && as[converted_size-1] != '\0') { + if (converted_size > 0 && as[converted_size-1] != '\0') { DEBUG(6,("long string '%s', send without NULL termination (which was expected)\n", as)); } }