]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
librpc/ndr: Remove confusing case where returned string pointer "as" could be NULL
authorAndrew Bartlett <abartlet@samba.org>
Sun, 5 Nov 2023 21:18:47 +0000 (10:18 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 13 Nov 2023 01:28:36 +0000 (01:28 +0000)
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 <abartlet@samba.org>
Reviewed-by: Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
librpc/ndr/ndr_string.c

index d0b64dc6fd90ab841f8dfc7c5566c5132abc55c3..988243abb0bf80cb42b04d1c0058bbe233d1dc13 100644 (file)
@@ -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));
                }
        }