ndr: Handle the case of string array with all null terminated strings
authorMatthieu Patou <mat@matws.net>
Sat, 4 Sep 2010 16:08:05 +0000 (20:08 +0400)
committerMatthieu Patou <mat@matws.net>
Tue, 5 Oct 2010 07:19:40 +0000 (11:19 +0400)
librpc/ndr/ndr_string.c

index 2e04633963bccd2ee1da6fc089814ee231adfbd6..e1f3a5245add8e682714a9f3c26147d78e1d5d29 100644 (file)
@@ -456,7 +456,8 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string_array(struct ndr_pull *ndr, int ndr_f
        case LIBNDR_FLAG_STR_NULLTERM:
                /* 
                 * here the strings are null terminated
-                * but also the array is null terminated
+                * but also the array is null terminated if LIBNDR_FLAG_REMAINING
+                * is specified
                 */
                for (count = 0;; count++) {
                        TALLOC_CTX *tmp_ctx;
@@ -469,6 +470,11 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string_array(struct ndr_pull *ndr, int ndr_f
                        tmp_ctx = ndr->current_mem_ctx;
                        ndr->current_mem_ctx = a;
                        NDR_CHECK(ndr_pull_string(ndr, ndr_flags, &s));
+                       if ((ndr->data_size - ndr->offset) == 0 && ndr->flags & LIBNDR_FLAG_REMAINING)
+                       {
+                               a[count] = s;
+                               break;
+                       }
                        ndr->current_mem_ctx = tmp_ctx;
                        if (strcmp("", s)==0) {
                                a[count] = NULL;
@@ -491,11 +497,14 @@ _PUBLIC_ enum ndr_err_code ndr_pull_string_array(struct ndr_pull *ndr, int ndr_f
                 * but serarated by a null terminator
                 *
                 * which means the same as:
-                * very string is null terminated exept the last
+                * Every string is null terminated exept the last
                 * string is terminated by the end of the buffer
                 *
                 * as LIBNDR_FLAG_STR_NULLTERM also end at the end
                 * of the buffer, we can pull each string with this flag
+                *
+                * The big difference with the case LIBNDR_FLAG_STR_NOTERM +
+                * LIBNDR_FLAG_REMAINING is that the last string will not be null terminated
                 */
                ndr->flags &= ~(LIBNDR_FLAG_STR_NOTERM|LIBNDR_FLAG_REMAINING);
                ndr->flags |= LIBNDR_FLAG_STR_NULLTERM;
@@ -545,8 +554,11 @@ _PUBLIC_ enum ndr_err_code ndr_push_string_array(struct ndr_push *ndr, int ndr_f
                for (count = 0; a && a[count]; count++) {
                        NDR_CHECK(ndr_push_string(ndr, ndr_flags, a[count]));
                }
-
-               NDR_CHECK(ndr_push_string(ndr, ndr_flags, ""));
+               /* If LIBNDR_FLAG_REMAINING then we do not add a null terminator to the array */
+               if (!(flags & LIBNDR_FLAG_REMAINING))
+               {
+                       NDR_CHECK(ndr_push_string(ndr, ndr_flags, ""));
+               }
                break;
 
        case LIBNDR_FLAG_STR_NOTERM: