[Top][All Lists]

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

[gpsd-dev] [PATCH 1/3] Fixes crash when quitting gpsmon in -a mode.

From: Fred Wright
Subject: [gpsd-dev] [PATCH 1/3] Fixes crash when quitting gpsmon in -a mode.
Date: Fri, 16 Sep 2016 18:18:26 -0700

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.

Typing a "q" in -a mode now outputs a prompt (an incorrect one,
but that's another story) and can then quits without crashing.
 gpsmon.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gpsmon.c b/gpsmon.c
index ea0991b..0a7c8eb 100644
--- a/gpsmon.c
+++ b/gpsmon.c
@@ -1439,8 +1439,9 @@ int main(int argc, char **argv)
                        (void)fputs(promptgen(), stdout);
                        (void)fputs("> ", stdout);
-                       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))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]