From 8e73b652f92795dcb35cd3826c88926e8072ea31 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 16 Mar 2009 21:17:29 +1100 Subject: [PATCH 1/1] Rework trivial msrpc parser to use convert_string_talloc() Also avoid still string conversions when trying to match NTLMSSP in the header of the NTLMSSP packet. This also changes a few things to avoid const warnings. Andrew Bartlett --- libcli/auth/msrpc_parse.c | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/libcli/auth/msrpc_parse.c b/libcli/auth/msrpc_parse.c index 969845d6c55..6c60258ad3a 100644 --- a/libcli/auth/msrpc_parse.c +++ b/libcli/auth/msrpc_parse.c @@ -209,7 +209,7 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, { int i; va_list ap; - const char **ps, *s; + char **ps, *s; DATA_BLOB *b; size_t head_ofs = 0; uint16_t len1, len2; @@ -228,9 +228,9 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, len2 = SVAL(blob->data, head_ofs); head_ofs += 2; ptr = IVAL(blob->data, head_ofs); head_ofs += 4; - ps = (const char **)va_arg(ap, char **); + ps = va_arg(ap, char **); if (len1 == 0 && len2 == 0) { - *ps = ""; + *ps = discard_const(""); } else { /* make sure its in the right format - be strict */ if ((len1 != len2) || (ptr + len1 < ptr) || (ptr + len1 < len1) || (ptr + len1 > blob->length)) { @@ -249,15 +249,15 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, } if (0 < len1) { - pull_string(p, blob->data + ptr, p_len, - len1, STR_UNICODE|STR_NOALIGN); - (*ps) = talloc_strdup(mem_ctx, p); - if (!(*ps)) { + size_t pull_len; + if (!convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, + blob->data + ptr, len1, + ps, &pull_len, false)) { ret = false; goto cleanup; } } else { - (*ps) = ""; + (*ps) = discard_const(""); } } break; @@ -267,10 +267,10 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, len2 = SVAL(blob->data, head_ofs); head_ofs += 2; ptr = IVAL(blob->data, head_ofs); head_ofs += 4; - ps = (const char **)va_arg(ap, char **); + ps = (char **)va_arg(ap, char **); /* make sure its in the right format - be strict */ if (len1 == 0 && len2 == 0) { - *ps = ""; + *ps = discard_const(""); } else { if ((len1 != len2) || (ptr + len1 < ptr) || (ptr + len1 < len1) || (ptr + len1 > blob->length)) { ret = false; @@ -284,15 +284,16 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, } if (0 < len1) { - pull_string(p, blob->data + ptr, p_len, - len1, STR_ASCII|STR_NOALIGN); - (*ps) = talloc_strdup(mem_ctx, p); - if (!(*ps)) { + size_t pull_len; + + if (!convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, + blob->data + ptr, len1, + ps, &pull_len, false)) { ret = false; goto cleanup; } } else { - (*ps) = ""; + (*ps) = discard_const(""); } } break; @@ -344,19 +345,18 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx, s = va_arg(ap, char *); if (blob->data + head_ofs < (uint8_t *)head_ofs || - blob->data + head_ofs < blob->data) { + blob->data + head_ofs < blob->data || + (head_ofs + (strlen(s) + 1)) > blob->length) { ret = false; goto cleanup; } - head_ofs += pull_string(p, - blob->data+head_ofs, p_len, - blob->length - head_ofs, - STR_ASCII|STR_TERMINATE); - if (strcmp(s, p) != 0) { + if (memcmp(blob->data + head_ofs, s, strlen(s)+1) != 0) { ret = false; goto cleanup; } + head_ofs += (strlen(s) + 1); + break; } } -- 2.34.1