From: Joseph Sutton Date: Thu, 13 Jul 2023 02:59:52 +0000 (+1200) Subject: libndr:ndr: Allow only one string encoding flag X-Git-Tag: talloc-2.4.2~689 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b693597b0db6425e5d11b067f5b8aea301dca76;p=thirdparty%2Fsamba.git libndr:ndr: Allow only one string encoding flag Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h index 3a453b5b168..5f84b0be7df 100644 --- a/librpc/ndr/libndr.h +++ b/librpc/ndr/libndr.h @@ -170,6 +170,12 @@ struct ndr_print { LIBNDR_FLAG_STR_RAW8 | \ 0) +#define LIBNDR_ENCODING_FLAGS (0U | \ + LIBNDR_FLAG_STR_ASCII | \ + LIBNDR_FLAG_STR_UTF8 | \ + LIBNDR_FLAG_STR_RAW8 | \ + 0) + /* * Mark an element as SECRET, it won't be printed by * via ndr_print* unless NDR_PRINT_SECRETS is specified. diff --git a/librpc/ndr/ndr_string.c b/librpc/ndr/ndr_string.c index ab34324139d..bb157b08492 100644 --- a/librpc/ndr/ndr_string.c +++ b/librpc/ndr/ndr_string.c @@ -44,29 +44,36 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string(struct ndr_pull *ndr, ndr_flags_type chset = CH_UTF16BE; } - if (flags & LIBNDR_FLAG_STR_ASCII) { - chset = CH_DOS; - byte_mul = 1; - flags &= ~LIBNDR_FLAG_STR_ASCII; - } - /* * We will check this flag, but from the unmodified * ndr->flags, so just remove it from flags */ flags &= ~LIBNDR_FLAG_STR_NO_EMBEDDED_NUL; - if (flags & LIBNDR_FLAG_STR_UTF8) { + switch (flags & LIBNDR_ENCODING_FLAGS) { + case 0: + break; + + case LIBNDR_FLAG_STR_ASCII: + chset = CH_DOS; + byte_mul = 1; + break; + + case LIBNDR_FLAG_STR_UTF8: chset = CH_UTF8; byte_mul = 1; - flags &= ~LIBNDR_FLAG_STR_UTF8; - } + break; - if (flags & LIBNDR_FLAG_STR_RAW8) { + case LIBNDR_FLAG_STR_RAW8: do_convert = 0; byte_mul = 1; - flags &= ~LIBNDR_FLAG_STR_RAW8; + break; + + default: + return ndr_pull_error(ndr, NDR_ERR_STRING, "Bad string flags 0x%"PRI_LIBNDR_FLAGS"\n", + ndr->flags & LIBNDR_STRING_FLAGS); } + flags &= ~LIBNDR_ENCODING_FLAGS; flags &= ~LIBNDR_FLAG_STR_CONFORMANT; if (flags & LIBNDR_FLAG_STR_CHARLEN) { @@ -260,29 +267,36 @@ _PUBLIC_ enum ndr_err_code ndr_push_string(struct ndr_push *ndr, ndr_flags_type s_len = s?strlen(s):0; - if (flags & LIBNDR_FLAG_STR_ASCII) { - chset = CH_DOS; - byte_mul = 1; - flags &= ~LIBNDR_FLAG_STR_ASCII; - } - /* * We will check this flag, but from the unmodified * ndr->flags, so just remove it from flags */ flags &= ~LIBNDR_FLAG_STR_NO_EMBEDDED_NUL; - if (flags & LIBNDR_FLAG_STR_UTF8) { + switch (flags & LIBNDR_ENCODING_FLAGS) { + case 0: + break; + + case LIBNDR_FLAG_STR_ASCII: + chset = CH_DOS; + byte_mul = 1; + break; + + case LIBNDR_FLAG_STR_UTF8: chset = CH_UTF8; byte_mul = 1; - flags &= ~LIBNDR_FLAG_STR_UTF8; - } + break; - if (flags & LIBNDR_FLAG_STR_RAW8) { + case LIBNDR_FLAG_STR_RAW8: do_convert = 0; byte_mul = 1; - flags &= ~LIBNDR_FLAG_STR_RAW8; + break; + + default: + return ndr_push_error(ndr, NDR_ERR_STRING, "Bad string flags 0x%"PRI_LIBNDR_FLAGS"\n", + ndr->flags & LIBNDR_STRING_FLAGS); } + flags &= ~LIBNDR_ENCODING_FLAGS; flags &= ~LIBNDR_FLAG_STR_CONFORMANT;