summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-03-09 14:55:20 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-03-09 14:55:20 +0000
commita6bf685ec3f64c3eae2d799aa1ebbdaa8f1de236 (patch)
treeda95ae608aa55f8d8f97ec9bacc091f6b675c7a6
parentbefe1eaba3c5bbd09da277a77acae6d0fe4fbca0 (diff)
downloadgpsd-a6bf685ec3f64c3eae2d799aa1ebbdaa8f1de236.tar.gz
Improve error detection from gpsd_hexpack().
-rw-r--r--gpsd.c13
-rw-r--r--gpsmon.c18
-rw-r--r--hex.c2
3 files changed, 19 insertions, 14 deletions
diff --git a/gpsd.c b/gpsd.c
index 9362efa5..de0749bb 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -1332,13 +1332,18 @@ static void handle_control(int sfd, char *buf)
*eq++ = '\0';
len = strlen(eq)+5;
if ((chp = find_device(stash)) != NULL) {
- gpsd_report(LOG_INF,"<= control(%d): writing fromhex(%s) to %s\n", sfd, eq, stash);
/* NOTE: this destroys the original buffer contents */
len = (size_t)gpsd_hexpack(eq, eq, len);
- ignore_return(write(chp->gpsdata.gps_fd, eq, len));
- ignore_return(write(sfd, "OK\n", 3));
+ if (len < 0)
+ gpsd_report(LOG_INF,"<= control(%d): invalid hex string (error %d)\n", sfd, len);
+ else
+ {
+ gpsd_report(LOG_INF,"<= control(%d): writing fromhex(%s) to %s\n", sfd, eq, stash);
+ ignore_return(write(chp->gpsdata.gps_fd, eq, len));
+ ignore_return(write(sfd, "OK\n", 3));
+ }
} else {
- gpsd_report(LOG_INF,"<= control(%d): %s not active \n", sfd, stash);
+ gpsd_report(LOG_INF,"<= control(%d): %s not active\n", sfd, stash);
ignore_return(write(sfd, "ERROR\n", 6));
}
}
diff --git a/gpsmon.c b/gpsmon.c
index b67722a2..cea6f63b 100644
--- a/gpsmon.c
+++ b/gpsmon.c
@@ -214,8 +214,6 @@ static void monitor_dump_send(void)
bool monitor_control_send(/*@in@*/unsigned char *buf, size_t len)
{
- monitor_dump_send();
-
if (controlfd == -1)
return false;
else {
@@ -246,7 +244,8 @@ bool monitor_control_send(/*@in@*/unsigned char *buf, size_t len)
assert(read(controlfd, buf, 8) != -1);
/*@ +sefparams @*/
}
- return ((size_t)st == len);
+ monitor_dump_send();
+ return (st != -1);
}
}
#endif /* ALLOW_CONTROLSEND */
@@ -817,15 +816,16 @@ int main (int argc, char **argv)
if (active == NULL)
monitor_complain("No device defined yet");
else {
- len = gpsd_hexpack(arg, (char*)buf, len);
- if (len == -1)
- monitor_complain("Invalid hex string");
- else if ((*active)->driver->control_send != NULL)
- (void)monitor_control_send(buf, (size_t)len);
- else
+ len = gpsd_hexpack(arg, (char*)buf, strlen(arg));
+ if (len < 0)
+ monitor_complain("Invalid hex string (error %d)", len);
+ else if ((*active)->driver->control_send == NULL)
monitor_complain("Device type has no control-send method.");
+ else if (!monitor_control_send(buf, (size_t)len))
+ monitor_complain("Control send failed.");
}
break;
+
#endif /* ALLOW_CONTROLSEND */
default:
diff --git a/hex.c b/hex.c
index 2c7170a0..f09f6159 100644
--- a/hex.c
+++ b/hex.c
@@ -58,7 +58,7 @@ int gpsd_hexpack(char *src, char *dst, size_t len){
l = (int)(strlen(src) / 2);
if ((l < 1) || ((size_t)l > len))
- return -1;
+ return -2;
bzero(dst, (int)len);
for (i = 0; i < l; i++)