ndrdump: Still print --dump bytes after parse failure
authorAndrew Bartlett <abartlet@samba.org>
Tue, 19 Nov 2019 21:45:02 +0000 (10:45 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 20 Nov 2019 04:41:28 +0000 (04:41 +0000)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
librpc/tools/ndrdump.c

index e2570bd4e493e5f005d2f151cfed1903c317ee5e..f02b1edab0261d2bc071183a54514e245b91f98b 100644 (file)
@@ -594,17 +594,22 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
        printf("pull returned %s\n",
               ndr_map_error2string(ndr_err));
 
-       if (!print_after_parse_failure && !NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               TALLOC_FREE(mem_ctx);
-               exit(2);
-       }
-
        if (ndr_pull->offset > ndr_pull->relative_highest_offset) {
                highest_ofs = ndr_pull->offset;
        } else {
                highest_ofs = ndr_pull->relative_highest_offset;
        }
 
+       if (dumpdata) {
+               printf("%d bytes consumed\n", highest_ofs);
+               ndrdump_data(blob.data, blob.length, dumpdata);
+       }
+
+       if (!print_after_parse_failure && !NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               TALLOC_FREE(mem_ctx);
+               exit(2);
+       }
+
        if (highest_ofs != ndr_pull->data_size) {
                printf("WARNING! %d unread bytes\n", ndr_pull->data_size - highest_ofs);
                ndrdump_data(ndr_pull->data+highest_ofs,
@@ -612,9 +617,10 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
                             dumpdata);
        }
 
-       if (dumpdata) {
-               printf("%d bytes consumed\n", highest_ofs);
-               ndrdump_data(blob.data, blob.length, dumpdata);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               printf("WARNING: pull of %s was incomplete, "
+                      "therefore the parse below may SEGFAULT\n",
+                       f->name);
        }
 
        f->ndr_print(ndr_print, format, flags, st);