~ubuntu-branches/debian/squeeze/ntp/squeeze-201010051545

« back to all changes in this revision

Viewing changes to ntpd/refclock_arbiter.c

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2009-01-05 21:10:03 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090105211003-mh6zc3um4k1uhsj7
Tags: 1:4.2.4p4+dfsg-8
It did not properly check the return value of EVP_VerifyFinal
which results in an malformed DSA signature being treated as
a good signature rather than as an error.  (CVE-2009-0021)

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
 *      ee = hardware errors
77
77
 *
78
78
 * If flag4 is set, an additional line consisting of the receiver
79
 
 * latitude (LA), longitude (LO) and elevation (LH) (meters) is written
80
 
 * to this file. If channel B is enabled for deviation mode and connected
81
 
 * to a 1-PPS signal, the last two numbers on the line are the deviation
82
 
 * and standard deviation averaged over the last 15 seconds.
 
79
 * latitude (LA), longitude (LO), elevation (LH) (meters), and data
 
80
 * buffer (DB) is written to this file. If channel B is enabled for
 
81
 * deviation mode and connected to a 1-PPS signal, the last two numbers
 
82
 * on the line are the deviation and standard deviation averaged over
 
83
 * the last 15 seconds.
 
84
 *
 
85
 * PPS calibration fudge time1 .001240
83
86
 */
84
87
 
85
88
/*
88
91
#define DEVICE          "/dev/gps%d" /* device name and unit */
89
92
#define SPEED232        B9600   /* uart speed (9600 baud) */
90
93
#define PRECISION       (-20)   /* precision assumed (about 1 us) */
91
 
#define REFID           "GPS " /* reference ID */
 
94
#define REFID           "GPS "  /* reference ID */
92
95
#define DESCRIPTION     "Arbiter 1088A/B GPS Receiver" /* WRU */
93
 
 
94
96
#define LENARB          24      /* format B5 timecode length */
95
 
#define MAXSTA          30      /* max length of status string */
96
 
#define MAXPOS          70      /* max length of position string */
 
97
#define MAXSTA          40      /* max length of status string */
 
98
#define MAXPOS          80      /* max length of position string */
97
99
 
98
100
/*
99
101
 * ARB unit control structure
212
214
        struct peer *peer;
213
215
        l_fp trtmp;
214
216
        int temp;
215
 
        u_char  syncchar;       /* synchronization indicator */
 
217
        u_char  syncchar;               /* synch indicator */
 
218
        char    tbuf[BMAX];             /* temp buffer */
216
219
 
217
220
        /*
218
221
         * Initialize pointers and read the timecode and timestamp
220
223
        peer = (struct peer *)rbufp->recv_srcclock;
221
224
        pp = peer->procptr;
222
225
        up = (struct arbunit *)pp->unitptr;
223
 
        temp = refclock_gtlin(rbufp, pp->a_lastcode, BMAX, &trtmp);
 
226
        temp = refclock_gtlin(rbufp, tbuf, BMAX, &trtmp);
224
227
 
225
228
        /*
226
229
         * Note we get a buffer and timestamp for both a <cr> and <lf>,
238
241
         */
239
242
        if (temp == 0)
240
243
                return;
 
244
 
241
245
        pp->lastrec = up->laststamp;
242
246
        up->laststamp = trtmp;
243
247
        if (temp < 3)
244
248
                return;
 
249
 
245
250
        if (up->tcswitch == 0) {
246
251
 
247
252
                /*
248
253
                 * Collect statistics. If nothing is recogized, just
249
254
                 * ignore; sometimes the clock doesn't stop spewing
250
 
                 * timecodes for awhile after the B0 commant.
 
255
                 * timecodes for awhile after the B0 command.
 
256
                 *
 
257
                 * If flag4 is not set, send TQ, SR, B5. If flag4 is
 
258
                 * sset, send TQ, SR, LA, LO, LH, DB, B5. When the
 
259
                 * median filter is full, send B0.
251
260
                 */
252
 
                if (!strncmp(pp->a_lastcode, "TQ", 2)) {
253
 
                        up->qualchar = pp->a_lastcode[2];
 
261
                if (!strncmp(tbuf, "TQ", 2)) {
 
262
                        up->qualchar = tbuf[2];
254
263
                        write(pp->io.fd, "SR", 2);
255
 
                } else if (!strncmp(pp->a_lastcode, "SR", 2)) {
256
 
                        strcpy(up->status, pp->a_lastcode + 2);
 
264
                        return;
 
265
 
 
266
                } else if (!strncmp(tbuf, "SR", 2)) {
 
267
                        strcpy(up->status, tbuf + 2);
257
268
                        if (pp->sloppyclockflag & CLK_FLAG4)
258
269
                                write(pp->io.fd, "LA", 2);
259
 
                        else {
 
270
                        else
260
271
                                write(pp->io.fd, "B5", 2);
261
 
                                up->tcswitch++;
262
 
                        }
263
 
                } else if (!strncmp(pp->a_lastcode, "LA", 2)) {
264
 
                        strcpy(up->latlon, pp->a_lastcode + 2);
 
272
                        return;
 
273
 
 
274
                } else if (!strncmp(tbuf, "LA", 2)) {
 
275
                        strcpy(up->latlon, tbuf + 2);
265
276
                        write(pp->io.fd, "LO", 2);
266
 
                } else if (!strncmp(pp->a_lastcode, "LO", 2)) {
 
277
                        return;
 
278
 
 
279
                } else if (!strncmp(tbuf, "LO", 2)) {
267
280
                        strcat(up->latlon, " ");
268
 
                        strcat(up->latlon, pp->a_lastcode + 2);
 
281
                        strcat(up->latlon, tbuf + 2);
269
282
                        write(pp->io.fd, "LH", 2);
270
 
                } else if (!strncmp(pp->a_lastcode, "LH", 2)) {
 
283
                        return;
 
284
 
 
285
                } else if (!strncmp(tbuf, "LH", 2)) {
271
286
                        strcat(up->latlon, " ");
272
 
                        strcat(up->latlon, pp->a_lastcode + 2);
 
287
                        strcat(up->latlon, tbuf + 2);
273
288
                        write(pp->io.fd, "DB", 2);
274
 
                } else if (!strncmp(pp->a_lastcode, "DB", 2)) {
 
289
                        return;
 
290
 
 
291
                } else if (!strncmp(tbuf, "DB", 2)) {
275
292
                        strcat(up->latlon, " ");
276
 
                        strcat(up->latlon, pp->a_lastcode + 2);
 
293
                        strcat(up->latlon, tbuf + 2);
277
294
                        record_clock_stats(&peer->srcadr, up->latlon);
 
295
#ifdef DEBUG
 
296
                        if (debug)
 
297
                                printf("arbiter: %s\n", up->latlon);
 
298
#endif
278
299
                        write(pp->io.fd, "B5", 2);
279
 
                        up->tcswitch++;
280
300
                }
281
 
                return;
282
301
        }
283
 
        pp->lencode = temp;
284
302
 
285
303
        /*
286
304
         * We get down to business, check the timecode format and decode
291
309
         * that the time quality character and receiver status string is
292
310
         * tacked on the end for clockstats display. 
293
311
         */
294
 
        if (pp->lencode == LENARB) {
295
 
                /*
296
 
                 * Timecode format B5: "i yy ddd hh:mm:ss.000   "
297
 
                 */
298
 
                pp->a_lastcode[LENARB - 2] = up->qualchar;
299
 
                strcat(pp->a_lastcode, up->status);
300
 
                syncchar = ' ';
301
 
                if (sscanf(pp->a_lastcode, "%c%2d %3d %2d:%2d:%2d",
302
 
                    &syncchar, &pp->year, &pp->day, &pp->hour,
303
 
                    &pp->minute, &pp->second) != 6) {
304
 
                        refclock_report(peer, CEVNT_BADREPLY);
305
 
                        write(pp->io.fd, "B0", 2);
306
 
                        return;
307
 
                }
308
 
        } else  {
309
 
                write(pp->io.fd, "B0", 2);
310
 
                return;
311
 
        }
312
312
        up->tcswitch++;
 
313
        if (up->tcswitch <= 1 || temp < LENARB)
 
314
                return;
 
315
 
 
316
        /*
 
317
         * Timecode format B5: "i yy ddd hh:mm:ss.000   "
 
318
         */
 
319
        strncpy(pp->a_lastcode, tbuf, BMAX);
 
320
        pp->a_lastcode[LENARB - 2] = up->qualchar;
 
321
        strcat(pp->a_lastcode, up->status);
 
322
        pp->lencode = strlen(pp->a_lastcode);
 
323
        syncchar = ' ';
 
324
        if (sscanf(pp->a_lastcode, "%c%2d %3d %2d:%2d:%2d",
 
325
            &syncchar, &pp->year, &pp->day, &pp->hour,
 
326
            &pp->minute, &pp->second) != 6) {
 
327
                refclock_report(peer, CEVNT_BADREPLY);
 
328
                write(pp->io.fd, "B0", 2);
 
329
                return;
 
330
        }
313
331
 
314
332
        /*
315
333
         * We decode the clock dispersion from the time quality
319
337
 
320
338
            case '0':           /* locked, max accuracy */
321
339
                pp->disp = 1e-7;
 
340
                pp->lastref = pp->lastrec;
322
341
                break;
323
342
 
324
343
            case '4':           /* unlock accuracy < 1 us */
369
388
                pp->leap = LEAP_NOTINSYNC;
370
389
        else
371
390
                pp->leap = LEAP_NOWARNING;
372
 
#ifdef DEBUG
373
 
        if (debug)
374
 
                printf("arbiter: timecode %d %s\n", pp->lencode,
375
 
                    pp->a_lastcode);
376
 
#endif
377
 
        if (up->tcswitch >= NSTAGE)
378
 
                write(pp->io.fd, "B0", 2);
379
391
 
380
392
        /*
381
393
         * Process the new sample in the median filter and determine the
383
395
         */
384
396
        if (!refclock_process(pp))
385
397
                refclock_report(peer, CEVNT_BADTIME);
 
398
        else if (peer->disp > MAXDISTANCE)
 
399
                refclock_receive(peer);
 
400
 
 
401
        if (up->tcswitch >= MAXSTAGE) {
 
402
                write(pp->io.fd, "B0", 2);
 
403
        }
386
404
}
387
405
 
388
406
 
404
422
         * Transmission occurs once per second, unless turned off by a
405
423
         * "B0". Note there is no checking on state, since this may not
406
424
         * be the only customer reading the clock. Only one customer
407
 
         * need poll the clock; all others just listen in. If nothing is
408
 
         * heard from the clock for two polls, declare a timeout and
409
 
         * keep going.
 
425
         * need poll the clock; all others just listen in.
410
426
         */
411
427
        pp = peer->procptr;
412
428
        up = (struct arbunit *)pp->unitptr;
 
429
        pp->polls++;
413
430
        up->tcswitch = 0;
414
 
        if (write(pp->io.fd, "TQ", 2) != 2) {
 
431
        if (write(pp->io.fd, "TQ", 2) != 2)
415
432
                refclock_report(peer, CEVNT_FAULT);
416
 
        } else {
417
 
                pp->polls++;
418
 
        }
 
433
 
 
434
        /*
 
435
         * Process median filter samples. If none received, declare a
 
436
         * timeout and keep going.
 
437
         */
419
438
        if (pp->coderecv == pp->codeproc) {
420
439
                refclock_report(peer, CEVNT_TIMEOUT);
421
440
                return;
422
441
        }
423
 
        pp->lastref = pp->lastrec;
424
442
        refclock_receive(peer);
425
443
        record_clock_stats(&peer->srcadr, pp->a_lastcode);
 
444
#ifdef DEBUG
 
445
        if (debug)
 
446
                printf("arbiter: timecode %d %s\n",
 
447
                   pp->lencode, pp->a_lastcode);
 
448
#endif
426
449
}
427
450
 
428
451
#else