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

« back to all changes in this revision

Viewing changes to clockstuff/clktest.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:
4
4
 * usage: clktest -b bps -f -t timeo -s cmd -c char1 -a char2 /dev/whatever
5
5
 */
6
6
 
7
 
#include <stdio.h>
8
 
#include <ctype.h>
9
 
#include <sys/types.h>
10
 
#include <sys/socket.h>
11
 
#include <signal.h>
12
 
#include <netinet/in.h>
13
 
#include <sys/ioctl.h>
14
 
#include <sys/time.h>
15
 
#include <sys/file.h>
16
 
#include <sgtty.h>
17
 
 
18
 
#include "../include/ntp_fp.h"
19
 
#include "../include/ntp.h"
20
 
#include "../include/ntp_unixtime.h"
 
7
#include "clktest-opts.h"
21
8
 
22
9
#define STREQ(a, b)     (*(a) == *(b) && strcmp((a), (b)) == 0)
23
10
 
28
15
#endif
29
16
 
30
17
#ifndef STREAM
31
 
#ifndef CLKLDISC
32
 
CLOCK_LINE_DISCIPLINE_NEEDED_BY_THIS_PROGRAM;
33
 
#endif
 
18
# ifndef CLKLDISC
 
19
    CLOCK_LINE_DISCIPLINE_NEEDED_BY_THIS_PROGRAM;
 
20
# endif
 
21
#else
 
22
# ifdef CLKLDISC
 
23
    ONLY_ONE_CLOCK_LINE_DISCIPLINE_FOR_THIS_PROGRAM;
 
24
# endif
34
25
#endif
35
26
 
36
27
/*
38
29
 */
39
30
#define BLOCKSIGMASK    (sigmask(SIGIO)|sigmask(SIGALRM))
40
31
 
41
 
/*
42
 
 * speed table
43
 
 */
44
 
struct speeds {
45
 
        int bps;
46
 
        int rate;
47
 
} speedtab[] = {
48
 
        { 300,          B300 },
49
 
        { 1200,         B1200 },
50
 
        { 2400,         B2400 },
51
 
        { 4800,         B4800 },
52
 
        { 9600,         B9600 },
53
 
        { 19200,        EXTA },
54
 
        { 38400,        EXTB },
55
 
        { 0,            0 }
56
 
};
57
 
 
58
 
char *progname;
59
 
int debug;
60
 
 
61
 
#ifdef CLKLDISC
62
 
#define DEFMAGIC        '\r'
63
 
#endif
64
 
 
65
 
#ifdef CLKLDISC
66
 
# ifdef STREAM
67
 
#  include <stropts.h>
68
 
#  ifdef HAVE_SYS_CLKDEFS_H
69
 
#   include <sys/clkdefs.h>
70
 
#  endif
71
 
#  define DEFMAGIC      "\r"
72
 
# endif
73
 
#endif
74
 
 
 
32
#define progname clktestOptions.pzProgName
 
33
 
75
34
struct timeval timeout = { 0 };
76
35
char *cmd = NULL;
77
36
int cmdlen;
78
 
int docmd = 0;
 
37
 
79
38
#ifdef CLKLDISC
80
39
u_long magic1 = DEFMAGIC;
81
40
u_long magic2 = DEFMAGIC;
82
41
#endif
83
 
#ifdef STREAM
84
 
char magic[32];
85
 
#endif
 
42
 
86
43
int speed = B9600;
87
44
int ttflags = RAW|EVENP|ODDP;
88
45
 
95
52
extern u_long ustotsmid[];
96
53
extern u_long ustotshi[];
97
54
 
 
55
int alarming();
 
56
int ioready();
 
57
 
98
58
/*
99
59
 * main - parse arguments and handle options
100
60
 */
104
64
        char *argv[]
105
65
        )
106
66
{
107
 
        int c;
108
 
        int errflg = 0;
109
 
        struct speeds *spd;
110
 
        u_long tmp;
111
67
        int fd;
112
68
        struct sgttyb ttyb;
113
69
        struct itimerval itimer;
114
 
        extern int ntp_optind;
115
 
        extern char *ntp_optarg;
116
 
        int alarming();
117
 
        int ioready();
118
70
 
119
 
        progname = argv[0];
120
71
#ifdef STREAM
121
72
        magic[0] = 0;
122
73
#endif
123
 
        while ((c = ntp_getopt(argc, argv, "a:b:c:dfs:t:")) != EOF)
124
 
            switch (c) {
125
 
#ifdef CLKLDISC
126
 
                case 'a':
127
 
#endif
128
 
                case 'c':
129
 
                    if (!atouint(ntp_optarg, &tmp)) {
130
 
                            (void) fprintf(stderr,
131
 
                                           "%s: argument for -%c must be integer\n",
132
 
                                           progname, c);
133
 
                            errflg++;
134
 
                            break;
135
 
                    }
136
 
#ifdef CLKLDISC
137
 
                    if (c == 'c')
138
 
                        magic1 = tmp;
139
 
                    else
140
 
                        magic2 = tmp;
141
 
#endif
142
 
#ifdef STREAM
143
 
                    magic[strlen(magic)+1] = '\0';
144
 
                    magic[strlen(magic)] = tmp;
145
 
#endif
146
 
                    break;
147
 
                case 'b':
148
 
                    if (!atouint(ntp_optarg, &tmp)) {
149
 
                            errflg++;
150
 
                            break;
151
 
                    }
152
 
                    spd = speedtab;
153
 
                    while (spd->bps != 0)
154
 
                        if ((int)tmp == spd->bps)
155
 
                            break;
156
 
                    if (spd->bps == 0) {
157
 
                            (void) fprintf(stderr,
158
 
                                           "%s: speed %lu is unsupported\n",
159
 
                                           progname, tmp);
160
 
                            errflg++;
161
 
                    } else {
162
 
                            speed = spd->rate;
163
 
                    }
164
 
                    break;
165
 
                case 'd':
166
 
                    ++debug;
167
 
                    break;
168
 
                case 'f':
169
 
                    ttflags |= CRMOD;
170
 
                    break;
171
 
                case 's':
172
 
                    cmdlen = strlen(ntp_optarg);
173
 
                    if (cmdlen == 0)
174
 
                        errflg++;
175
 
                    else
176
 
                        cmd = ntp_optarg;
177
 
                    break;
178
 
                case 't':
179
 
                    if (!atouint(ntp_optarg, &tmp))
180
 
                        errflg++;
181
 
                    else {
182
 
                            timeout.tv_sec = (long)tmp;
183
 
                            docmd = 1;
184
 
                    }
185
 
                    break;
186
 
                default:
187
 
                    errflg++;
188
 
                    break;
189
 
            }
190
 
        if (errflg || ntp_optind+1 != argc) {
191
 
                (void) fprintf(stderr,
192
 
#ifdef CLKLDISC
193
 
                               "usage: %s [-b bps] [-c magic1] [-a magic2] [-f] [-s cmd] [-t timeo]  tty_device\n",
194
 
#endif
195
 
#ifdef STREAM
196
 
                               "usage: %s [-b bps] [-c magic1] [-c magic2]... [-f] [-s cmd] [-t timeo]  tty_device\n",
197
 
#endif
198
 
                               progname);
199
 
                exit(2);
 
74
 
 
75
        {
 
76
            int ct = optionProcess( &clktestOptions, argc, argv );
 
77
            if (HAVE_OPT(COMMAND) && (strlen(OPT_ARG(COMMAND)) == 0)) {
 
78
                fputs( "The command option string must not be empty\n", stderr );
 
79
                USAGE( EXIT_FAILURE );
 
80
            }
 
81
 
 
82
            if ((argc -= ct) != 1) {
 
83
                fputs( "Missing tty device name\n", stderr );
 
84
                USAGE( EXIT_FAILURE );
 
85
            }
 
86
            argv += ct;
200
87
        }
201
 
 
202
88
#ifdef STREAM
203
89
        if (!strlen(magic))
204
90
            strcpy(magic,DEFMAGIC);
205
91
#endif
206
92
 
207
 
        if (docmd)
208
 
            fd = open(argv[ntp_optind], O_RDWR, 0777);
209
 
        else
210
 
            fd = open(argv[ntp_optind], O_RDONLY, 0777);
 
93
        fd = open(*argv, HAVE_OPT(TIMEOUT) ? O_RDWR : O_RDONLY, 0777);
211
94
        if (fd == -1) {
212
 
                (void) fprintf(stderr, "%s: open(%s): ", progname,
213
 
                               argv[ntp_optind]);
 
95
                fprintf(stderr, "%s: open(%s): ", progname, *argv);
214
96
                perror("");
215
97
                exit(1);
216
98
        }
270
152
 
271
153
 
272
154
        (void) gettimeofday(&lasttv, (struct timezone *)0);
273
 
        if (docmd) {
 
155
        if (HAVE_OPT(TIMEOUT)) {
274
156
                /*
275
157
                 * set non-blocking, async I/O on the descriptor
276
158
                 */
288
170
                 */
289
171
                wasalarmed = 0;
290
172
                (void) signal(SIGALRM, alarming);
 
173
                timeout.tv_sec = OPT_VALUE_TIMEOUT;
291
174
                itimer.it_interval = itimer.it_value = timeout;
292
175
                setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
293
176
                doboth(fd);
495
378
{
496
379
        int n;
497
380
 
498
 
        if (cmd == NULL || cmdlen <= 0)
 
381
        if (! HAVE_OPT(COMMAND))
499
382
            return;
500
383
 
501
384
        n = write(fd, cmd, cmdlen);