Bug 219689 - [PATCH] systat segfault when invoked with some invalid arguments
Summary: [PATCH] systat segfault when invoked with some invalid arguments
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.0-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs mailing list
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2017-05-31 19:08 UTC by Marko Turk
Modified: 2019-02-03 14:48 UTC (History)
2 users (show)

See Also:


Attachments
patch (826 bytes, text/plain)
2017-05-31 19:08 UTC, Marko Turk
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marko Turk 2017-05-31 19:08:46 UTC
Created attachment 183110 [details]
patch

Hi,

some combinations of invalid arguments can crash systat.

For example:
systat -vmstat -d
Segmentation fault (core dumped)

I've attached a patch that fixes this.

(gdb) bt
#0  strlen (str=0x0) at /usr/src/lib/libc/string/strlen.c:100
#1  0x0000000801170092 in strdup (str=0x0) at /usr/src/lib/libc/string/strdup.c:46
#2  0x0000000000403c12 in dsselect (args=0x0, select_mode=DS_SELECT_ADDONLY, maxshowdevs=7, s1=0x621e00) at /usr/src/usr.bin/systat/devs.c:267
#3  0x000000000040ff4e in cmdkre (cmd=<value optimized out>, args=0x0) at _ctype.h:107
#4  0x0000000000405955 in main (argc=<value optimized out>, argv=<value optimized out>) at /usr/src/usr.bin/systat/main.c:225
#5  0x0000000000402f1f in _start ()
#6  0x000000080063a000 in ?? ()
#7  0x0000000000000000 in ?? ()

/Marko
Comment 1 Ed Maste freebsd_committer 2017-09-13 23:07:37 UTC
Confirmed reproducible on 12-current r321400
Comment 2 commit-hook freebsd_committer 2019-01-20 19:48:35 UTC
A commit references this bug:

Author: gonzo
Date: Sun Jan 20 19:47:34 UTC 2019
New revision: 343222
URL: https://svnweb.freebsd.org/changeset/base/343222

Log:
  Fix crash in systat(4) when certain commands are called without arguments

  Add check for missing arguments to dsmatchselect and dsselect

  PR:		219689
  Submitted by:	Marko Turk <mt@markoturk.info>
  MFC after:	1 week

Changes:
  head/usr.bin/systat/devs.c
Comment 3 commit-hook freebsd_committer 2019-01-20 19:56:44 UTC
A commit references this bug:

Author: gonzo
Date: Sun Jan 20 19:55:54 UTC 2019
New revision: 343223
URL: https://svnweb.freebsd.org/changeset/base/343223

Log:
  Fix inconsistency in return values introduced by r343222

  Consistently return 1 or the case of missing arguments in both functions

  PR:		219689
  MFC after:	1 week
  X-MFC-With:	343222

Changes:
  head/usr.bin/systat/devs.c
Comment 4 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2019-01-20 19:57:26 UTC
Patch has bin committed, thanks for submitting it. I'll handle MFC in a week.
Comment 5 commit-hook freebsd_committer 2019-02-03 14:47:58 UTC
A commit references this bug:

Author: gonzo
Date: Sun Feb  3 14:47:22 UTC 2019
New revision: 343714
URL: https://svnweb.freebsd.org/changeset/base/343714

Log:
  MFC r343222-r343223, r343338

  r343222:
  Fix crash in systat(4) when certain commands are called without arguments

  Add check for missing arguments to dsmatchselect and dsselect

  PR:		219689
  Submitted by:	Marko Turk <mt@markoturk.info>

  r343223:
  Fix inconsistency in return values introduced by r343222

  Consistently return 1 or the case of missing arguments in both functions

  PR:		219689
  X-MFC-With:	343222

  r343338:
  Fix systat's :only command parser for the multiple arguments case

  According to systat(1) :only option is supposed to accept multiple drives
  but the parser for its arguments stops after first entry. Fix the parser
  logic to accept multiple drives.

  PR:		59220
  Reported by:	Andy Farkas <andyf@speednet.com.au>

Changes:
_U  stable/12/
  stable/12/usr.bin/systat/devs.c
Comment 6 commit-hook freebsd_committer 2019-02-03 14:48:01 UTC
A commit references this bug:

Author: gonzo
Date: Sun Feb  3 14:47:23 UTC 2019
New revision: 343714
URL: https://svnweb.freebsd.org/changeset/base/343714

Log:
  MFC r343222-r343223, r343338

  r343222:
  Fix crash in systat(4) when certain commands are called without arguments

  Add check for missing arguments to dsmatchselect and dsselect

  PR:		219689
  Submitted by:	Marko Turk <mt@markoturk.info>

  r343223:
  Fix inconsistency in return values introduced by r343222

  Consistently return 1 or the case of missing arguments in both functions

  PR:		219689
  X-MFC-With:	343222

  r343338:
  Fix systat's :only command parser for the multiple arguments case

  According to systat(1) :only option is supposed to accept multiple drives
  but the parser for its arguments stops after first entry. Fix the parser
  logic to accept multiple drives.

  PR:		59220
  Reported by:	Andy Farkas <andyf@speednet.com.au>

Changes:
_U  stable/12/
  stable/12/usr.bin/systat/devs.c