summaryrefslogtreecommitdiff
path: root/gpsmon.c
diff options
context:
space:
mode:
authorFred Wright <fw@fwright.net>2016-09-16 18:18:26 -0700
committerGary E. Miller <gem@rellim.com>2016-09-22 16:55:07 -0700
commit21eb174671474947688c5afee8e92a637b2fb149 (patch)
tree1d9db821380b7cfc4dfd635e09d8909661a9b1ec /gpsmon.c
parenta3ff750ce4d73dbdc7e7f017ef81f3f1df7347a4 (diff)
downloadgpsd-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.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/gpsmon.c b/gpsmon.c
index ea0991be..0a7c8eb9 100644
--- a/gpsmon.c
+++ b/gpsmon.c
@@ -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))