diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2009-03-09 14:55:20 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2009-03-09 14:55:20 +0000 |
commit | a6bf685ec3f64c3eae2d799aa1ebbdaa8f1de236 (patch) | |
tree | da95ae608aa55f8d8f97ec9bacc091f6b675c7a6 | |
parent | befe1eaba3c5bbd09da277a77acae6d0fe4fbca0 (diff) | |
download | gpsd-a6bf685ec3f64c3eae2d799aa1ebbdaa8f1de236.tar.gz |
Improve error detection from gpsd_hexpack().
-rw-r--r-- | gpsd.c | 13 | ||||
-rw-r--r-- | gpsmon.c | 18 | ||||
-rw-r--r-- | hex.c | 2 |
3 files changed, 19 insertions, 14 deletions
@@ -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)); } } @@ -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: @@ -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++) |