diff options
author | Fred Wright <fw@fwright.net> | 2016-09-16 18:18:26 -0700 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2016-09-22 16:55:07 -0700 |
commit | 21eb174671474947688c5afee8e92a637b2fb149 (patch) | |
tree | 1d9db821380b7cfc4dfd635e09d8909661a9b1ec /gpsmon.c | |
parent | a3ff750ce4d73dbdc7e7f017ef81f3f1df7347a4 (diff) | |
download | gpsd-21eb174671474947688c5afee8e92a637b2fb149.tar.gz |
Fixes crash when quitting gpsmon in -a mode.
There were two bugs in the alternate input code used in -a mode:
1) It was using strlen() instead of sizeof() to determine the
available space in the input buffer. This is uninitialized data,
making the result nondeterministic, though it would return zero
in the case observed.
2) It was failing to handle the NULL return from fgets() correctly,
resulting in a call to do_command() with a garbage argument. This
caused a segfault.
Also, casting the strlen/sizeof value to int was superfluous.
TESTED:
Typing a "q" in -a mode now outputs a prompt (an incorrect one,
but that's another story) and can then quits without crashing.
Signed-off-by: Gary E. Miller <gem@rellim.com>
Diffstat (limited to 'gpsmon.c')
-rw-r--r-- | gpsmon.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -1439,8 +1439,9 @@ int main(int argc, char **argv) (void)fputs(promptgen(), stdout); (void)fputs("> ", stdout); (void)putchar(inbuf[0]); - cmdline = fgets(inbuf+1, (int)strlen(inbuf)-1, stdin); - cmdline--; + cmdline = fgets(inbuf+1, sizeof(inbuf)-1, stdin); + if (cmdline) + cmdline--; } } if (cmdline != NULL && !do_command(cmdline)) |