68399e
From 7c26fab82d668199756ebf24a96c46c102250c6a Mon Sep 17 00:00:00 2001
68399e
From: Stefan Metzmacher <metze@samba.org>
68399e
Date: Mon, 9 May 2016 16:14:31 +0200
68399e
Subject: [PATCH] libcli/auth: let msrpc_parse() return talloc'ed empty strings
68399e
68399e
This make it more predictable for the callers.
68399e
68399e
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11912
68399e
BUG: https://bugzilla.redhat.com/show_bug.cgi?id=1334356
68399e
BUG: https://launchpad.net/bugs/1578576
68399e
68399e
Signed-off-by: Stefan Metzmacher <metze@samba.org>
68399e
68399e
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
68399e
Autobuild-Date(master): Mon May  9 22:27:21 CEST 2016 on sn-devel-144
68399e
68399e
(cherry picked from commit 58a83236294117d32d9883ac3024f81fa1730a87)
68399e
---
68399e
 libcli/auth/msrpc_parse.c | 24 ++++++++++++++++++++----
68399e
 1 file changed, 20 insertions(+), 4 deletions(-)
68399e
68399e
diff --git a/libcli/auth/msrpc_parse.c b/libcli/auth/msrpc_parse.c
68399e
index d499d9e..74a7bcc 100644
68399e
--- a/libcli/auth/msrpc_parse.c
68399e
+++ b/libcli/auth/msrpc_parse.c
68399e
@@ -262,7 +262,11 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx,
68399e
 
68399e
 			ps = va_arg(ap, char **);
68399e
 			if (len1 == 0 && len2 == 0) {
68399e
-				*ps = (char *)discard_const("");
68399e
+				*ps = talloc_strdup(mem_ctx, "");
68399e
+				if (*ps == NULL) {
68399e
+					ret = false;
68399e
+					goto cleanup;
68399e
+				}
68399e
 			} else {
68399e
 				/* make sure its in the right format - be strict */
68399e
 				if ((len1 != len2) || (ptr + len1 < ptr) || (ptr + len1 < len1) || (ptr + len1 > blob->length)) {
68399e
@@ -289,7 +293,11 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx,
68399e
 						goto cleanup;
68399e
 					}
68399e
 				} else {
68399e
-					(*ps) = (char *)discard_const("");
68399e
+					*ps = talloc_strdup(mem_ctx, "");
68399e
+					if (*ps == NULL) {
68399e
+						ret = false;
68399e
+						goto cleanup;
68399e
+					}
68399e
 				}
68399e
 			}
68399e
 			break;
68399e
@@ -302,7 +310,11 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx,
68399e
 			ps = (char **)va_arg(ap, char **);
68399e
 			/* make sure its in the right format - be strict */
68399e
 			if (len1 == 0 && len2 == 0) {
68399e
-				*ps = (char *)discard_const("");
68399e
+				*ps = talloc_strdup(mem_ctx, "");
68399e
+				if (*ps == NULL) {
68399e
+					ret = false;
68399e
+					goto cleanup;
68399e
+				}
68399e
 			} else {
68399e
 				if ((len1 != len2) || (ptr + len1 < ptr) || (ptr + len1 < len1) || (ptr + len1 > blob->length)) {
68399e
 					ret = false;
68399e
@@ -325,7 +337,11 @@ bool msrpc_parse(TALLOC_CTX *mem_ctx,
68399e
 						goto cleanup;
68399e
 					}
68399e
 				} else {
68399e
-					(*ps) = (char *)discard_const("");
68399e
+					*ps = talloc_strdup(mem_ctx, "");
68399e
+					if (*ps == NULL) {
68399e
+						ret = false;
68399e
+						goto cleanup;
68399e
+					}
68399e
 				}
68399e
 			}
68399e
 			break;
68399e
-- 
68399e
1.9.1
68399e