diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2014-10-09 22:34:58 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2014-12-09 08:35:07 -0500 |
commit | addd2215a078e3833bb2e06bd343180e70bb28e4 (patch) | |
tree | 7557c3084a7a00e3355104e691caf7d2ace937ff /gpsd.c | |
parent | 93a0316136a99f47cd13c121978ac4362f31c95b (diff) | |
download | gpsd-addd2215a078e3833bb2e06bd343180e70bb28e4.tar.gz |
Sanity check for too many devices on the command line.
All regression tests pass.
Diffstat (limited to 'gpsd.c')
-rw-r--r-- | gpsd.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -829,8 +829,11 @@ static void handle_control(int sfd, char *buf) "<= control(%d): adding %s\n", sfd, stash); if (gpsd_add_device(stash, NOWAIT)) ignore_return(write(sfd, "OK\n", 3)); - else + else { ignore_return(write(sfd, "ERROR\n", 6)); + gpsd_report(&context.errout, LOG_INF, + "control(%d): adding %s failed, too many devices active\n", sfd, stash); + } } } else if (buf[0] == '!') { /* split line after ! into device=string, send string to device */ @@ -1879,6 +1882,13 @@ int main(int argc, char *argv[]) } } + /* sanity check */ + if (argc - optind > MAXDEVICES) { + gpsd_report(&context.errout, LOG_ERROR, + "too many devices on command line\n"); + exit(1); + } + #ifdef SYSTEMD_ENABLE sd_socket_count = sd_get_socket_count(); if (sd_socket_count > 0 && control_socket != NULL) { |