[ntp:questions] nmea patch

Per Hedeland per at hedeland.org
Sat Dec 20 15:53:52 UTC 2008


In article <6ZydnaSrfpna1dbUnZ2dnUVZ_qrinZ2d at megapath.net>
hal-usenet at ip-64-139-1-69.sjc.megapath.net (Hal Murray) writes:
>In article <ywn94p108yb7.fsf at ntp1.isc.org>,
> Harlan Stenn <stenn at ntp.org> writes:
>>I'm glad it is working for you and I'd be even happier if we could figure
>>out why the NULL string got where it did earlier, as ntpd should never drop
>>core like that.
>
>It might be just a simple bug.  The code in that area says:
>
>          if ((len = readlink(device,buffer,sizeof(buffer))) == -1)
>            return(0);
>          buffer[len] = 0;
>
>          if ((nmea_host = strtok(buffer,":")) == NULL)
>            return(0);
>
>          nmea_port = atoi(strtok(NULL,":"));
>
>The idea is that if you are using the nmead, then /dev/gps0
>will be a synbilic link to someting like "server:port" so
>nmea_host will be the server and nmea_port will be the port number.

And if it isn't, but rather a link to (say) /dev/ttyS0, nmea_host will
get the whole "/dev/ttyS0" (the first "colon-separated token"), the
second strtok() will return NULL since there are no more "tokens", and
atoi(NULL) shouldn't be expected to do anything more meaningful than
crash. Better code would be

          char *p;
          ...
          if ((p = strtok(NULL,":")) == NULL)
             return 0;
          nmea_port = atoi(p);

--Per Hedeland
per at hedeland.org




More information about the questions mailing list