1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

ndrdump: add --stop-on-parse-failure

If a data stream fails to parse as an NDR object, the default ndrdump
action is to try to print those structures anyway, resulting perhaps in
a NULL dereference. Sometimes you don't want to see that because it isn't
very interesting and makes it harder to distinguish a crash in the parse
routines. So --stop-on-parse-failure will skip the print and validate
stages altogether if the parse failed.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Pair-programmed-with: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Douglas Bagnall 2019-10-30 03:05:22 +00:00 committed by Douglas Bagnall
parent a106ceb7bf
commit dfbb304958

View File

@ -261,8 +261,18 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
bool assume_ndr64 = false;
bool quiet = false;
bool hex_input = false;
bool stop_on_parse_failure = false;
int opt;
enum {OPT_CONTEXT_FILE=1000, OPT_VALIDATE, OPT_DUMP_DATA, OPT_LOAD_DSO, OPT_NDR64, OPT_QUIET, OPT_HEX_INPUT};
enum {
OPT_CONTEXT_FILE=1000,
OPT_VALIDATE,
OPT_DUMP_DATA,
OPT_LOAD_DSO,
OPT_NDR64,
OPT_QUIET,
OPT_HEX_INPUT,
OPT_STOP_ON_PARSE_FAILURE,
};
struct poptOption long_options[] = {
POPT_AUTOHELP
{"context-file", 'c', POPT_ARG_STRING, NULL, OPT_CONTEXT_FILE, "In-filename to parse first", "CTX-FILE" },
@ -272,6 +282,8 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
{"ndr64", 0, POPT_ARG_NONE, NULL, OPT_NDR64, "Assume NDR64 data", NULL },
{"quiet", 0, POPT_ARG_NONE, NULL, OPT_QUIET, "Don't actually dump anything", NULL },
{"hex-input", 0, POPT_ARG_NONE, NULL, OPT_HEX_INPUT, "Read the input file in as a hex dump", NULL },
{"stop-on-parse-failure", 0, POPT_ARG_NONE, NULL, OPT_STOP_ON_PARSE_FAILURE,
"Do not try to print structures that fail to parse.", NULL },
POPT_COMMON_SAMBA
POPT_COMMON_VERSION
{ NULL }
@ -316,6 +328,9 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
case OPT_HEX_INPUT:
hex_input = true;
break;
case OPT_STOP_ON_PARSE_FAILURE:
stop_on_parse_failure = true;
break;
}
}
@ -509,6 +524,11 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
printf("pull returned %s\n", nt_errstr(status));
if (stop_on_parse_failure && !NT_STATUS_IS_OK(status)) {
printf("not printing because --stop-on-parse-failure\n");
exit(1);
}
if (ndr_pull->offset > ndr_pull->relative_highest_offset) {
highest_ofs = ndr_pull->offset;
} else {