pcp
[Top] [All Lists]

[PATCH] Make pmlogextract not crash with unknown arguments

To: pcp@xxxxxxxxxxx
Subject: [PATCH] Make pmlogextract not crash with unknown arguments
From: Michele Baldessari <michele@xxxxxxxxxx>
Date: Wed, 21 May 2014 09:30:06 +0100
Cc: Michele Baldessari <michele@xxxxxxxxxx>
Delivered-to: pcp@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=acksyn.org; h= x-mailer:message-id:date:date:subject:subject:from:from:received :received; s=2010; t=1400661016; bh=mdLRe4asGNqbVKGMIJxQ/hrN3zmH BAtC5lxoNCVVcOk=; b=jcQA5kqluwbnHjtEdlrC9otAJcU5Fwb1L1a461vD7WzF nwroJR3PSVUQuli1XkzSddU+drQfQZ1t2d/Opt1+yndqPOEOsZBxbSNiJbkIwzfo XyLaUWFmg/mlUQLbSPYfx/flGlXNAbSAZ/8odak/KPVUt3sL/Fx6+AvOK3Bd1LQ=
pmlogextract with unknown arguments segfaults:
$ gdb --args pmlogextract --help
Segmentation fault (core dumped)
(gdb) bt
  #0  __strncmp_ssse3 () at ../sysdeps/x86_64/strcmp.S:209
  #1  0x00007ffff7da818f in pmgetopt_r (argc=argc@entry=2,
  argv=argv@entry=0x7fffffffdbb8, d=d@entry=0x60d2e0 <opts>)
    at getopt.c:1101
  #2  0x0000000000405389 in parseargs (argc=argc@entry=2,
  argv=argv@entry=0x7fffffffdbb8) at pmlogextract.c:1222
  #3  0x0000000000402a05 in main (argc=2, argv=0x7fffffffdbb8) at
  pmlogextract.c:1635    at getopt.c:1101

Make sure we signal the end of the options list to pmgetopt via 
PMAPI_OPTIONS_END
so that it won't segfault any longer:
./src/pmlogextract/pmlogextract --help
pmlogextract: unrecognized option '--help'
Usage: pmlogextract [options] input-archive output-archive
...

Signed-off-by: Michele Baldessari <michele@xxxxxxxxxx>
---
 src/pmlogextract/pmlogextract.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/pmlogextract/pmlogextract.c b/src/pmlogextract/pmlogextract.c
index f0513180eaa9..7c202925f3e2 100644
--- a/src/pmlogextract/pmlogextract.c
+++ b/src/pmlogextract/pmlogextract.c
@@ -40,7 +40,8 @@ static pmLongOptions longopts[] = {
     { "", 1, 'v', "SAMPLES", "switch log volumes after this many samples" },
     { "", 0, 'w', 0, "ignore day/month/year" },
     PMOPT_TIMEZONE,
-    PMOPT_HOSTZONE
+    PMOPT_HOSTZONE,
+    PMAPI_OPTIONS_END
 };
 
 static pmOptions opts = {
-- 
1.9.0

<Prev in Thread] Current Thread [Next in Thread>