From 9330f3339d15b731d44b8f74fa9f59837ef91dbd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 30 Mar 2011 12:58:33 -0700 Subject: [PATCH] Make ndr_push_charset robust in the face of zero destination length. --- librpc/ndr/ndr_string.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/librpc/ndr/ndr_string.c b/librpc/ndr/ndr_string.c index 610676cf780..d750e2c15a0 100644 --- a/librpc/ndr/ndr_string.c +++ b/librpc/ndr/ndr_string.c @@ -705,17 +705,20 @@ _PUBLIC_ enum ndr_err_code ndr_push_charset(struct ndr_push *ndr, int ndr_flags, required = byte_mul * length; NDR_PUSH_NEED_BYTES(ndr, required); - ret = convert_string(CH_UNIX, chset, + + if (required) { + ret = convert_string(CH_UNIX, chset, var, strlen(var), ndr->data+ndr->offset, required, false); - if (ret == -1) { - return ndr_push_error(ndr, NDR_ERR_CHARCNV, - "Bad character conversion"); - } + if (ret == -1) { + return ndr_push_error(ndr, NDR_ERR_CHARCNV, + "Bad character conversion"); + } - /* Make sure the remaining part of the string is filled with zeroes */ - if (ret < required) { - memset(ndr->data+ndr->offset+ret, 0, required-ret); + /* Make sure the remaining part of the string is filled with zeroes */ + if (ret < required) { + memset(ndr->data+ndr->offset+ret, 0, required-ret); + } } ndr->offset += required; -- 2.11.4.GIT