public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: fstests@vger.kernel.org
Subject: [PATCH] fstests: log-writes: Handle unrecognized options to prevent segfault
Date: Thu,  8 Aug 2019 15:29:40 +0800	[thread overview]
Message-ID: <20190808072940.18684-1-wqu@suse.com> (raw)

[BUG]
When using --help parameter (unrecognized) after valid --log/--replay,
log-writes just crashes:
  Starting program: replay-log --log /dev/test/test  --replay /dev/test/scratch1 --help
  /home/adam/xfstests-dev/src/log-writes/replay-log: unrecognized option '--help'

  Program received signal SIGSEGV, Segmentation fault.
  0x00007ffff7f5cc55 in __strlen_avx2 () from /usr/lib/libc.so.6
  (gdb) bt
  #0  0x00007ffff7f5cc55 in __strlen_avx2 () from /usr/lib/libc.so.6
  #1  0x00007ffff7e89363 in strdup () from /usr/lib/libc.so.6
  #2  0x00005555555554ac in main (argc=6, argv=0x7fffffffea78)
      at replay-log.c:219

[CAUSE]
We didn't check return value from getopt_long() for unrecognized
parameter, thus we reuse the old opt_index, and if that option needs an
parameter, we will access optarg which can be NULL and cause segfault.

[FIX]
Check return value from getopt_long() for '?' to handle unrecognized
options correctly.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 src/log-writes/replay-log.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/log-writes/replay-log.c b/src/log-writes/replay-log.c
index c16df40e..829b18e2 100644
--- a/src/log-writes/replay-log.c
+++ b/src/log-writes/replay-log.c
@@ -162,6 +162,8 @@ int main(int argc, char **argv)
 		case 'v':
 			log_writes_verbose++;
 			continue;
+		case '?':
+			usage();
 		default:
 			break;
 		}
-- 
2.22.0

                 reply	other threads:[~2019-08-08  7:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190808072940.18684-1-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=fstests@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox