[PATCH] fstests: log-writes: Handle unrecognized options to prevent segfault

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



[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@xxxxxxxx>
---
 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




[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux