From 7be90e6e877030c83e4dc0061cfa4687739362ee Mon Sep 17 00:00:00 2001 From: Lorenzo Cogotti Date: Sun, 22 Aug 2021 10:14:04 +0200 Subject: [PATCH] [tools/peerindex] Prevent possible clobbering of argc,argv after longjmp() --- tools/peerindex/peerindex.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/peerindex/peerindex.c b/tools/peerindex/peerindex.c index eee55c0..feeebc8 100644 --- a/tools/peerindex/peerindex.c +++ b/tools/peerindex/peerindex.c @@ -407,20 +407,23 @@ int main(int argc, char **argv) argc -= optind; argv += optind; - // Move to filtering rules and compile them - if (argc == 0) { + // Take file list + char **files = argv; + int nfiles = argc; + + if (nfiles == 0) { // If no FILES are provided, read from stdin static const char *const stdinFile[] = { "-" }; - argv = (char **) stdinFile; - argc = ARRAY_SIZE(stdinFile); + files = (char **) stdinFile; + nfiles = ARRAY_SIZE(stdinFile); } volatile int i = 0; setjmp(S.dropFileFrame); // NOTE: The ONLY place where this is set - while (i < argc) - Peerindex_ProcessMrtDump(argv[i++]); + while (i < nfiles) + Peerindex_ProcessMrtDump(files[i++]); if (S.outfOps->Close) S.outfOps->Close(S.outf);