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

« back to all changes in this revision

Viewing changes to libparse/data_mbg.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:
1
1
/*
2
 
 * /src/NTP/ntp-4/libparse/data_mbg.c,v 4.3 1999/02/21 12:17:42 kardel RELEASE_19991128_A
 
2
 * /src/NTP/REPOSITORY/ntp4-dev/libparse/data_mbg.c,v 4.8 2006/06/22 18:40:01 kardel RELEASE_20060622_A
 
3
 *
 
4
 * data_mbg.c,v 4.8 2006/06/22 18:40:01 kardel RELEASE_20060622_A
3
5
 *
4
6
 * $Created: Sun Jul 20 12:08:14 1997 $
5
7
 *
6
 
 * Copyright (C) 1997, 1998 by Frank Kardel
 
8
 * Copyright (c) 1997-2005 by Frank Kardel <kardel <AT> ntp.org>
 
9
 *
 
10
 * Redistribution and use in source and binary forms, with or without
 
11
 * modification, are permitted provided that the following conditions
 
12
 * are met:
 
13
 * 1. Redistributions of source code must retain the above copyright
 
14
 *    notice, this list of conditions and the following disclaimer.
 
15
 * 2. Redistributions in binary form must reproduce the above copyright
 
16
 *    notice, this list of conditions and the following disclaimer in the
 
17
 *    documentation and/or other materials provided with the distribution.
 
18
 * 3. Neither the name of the author nor the names of its contributors
 
19
 *    may be used to endorse or promote products derived from this software
 
20
 *    without specific prior written permission.
 
21
 *
 
22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 
23
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
24
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
25
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 
26
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
27
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
28
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
29
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
30
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
31
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
32
 * SUCH DAMAGE.
 
33
 *
7
34
 */
8
35
 
9
36
#ifdef PARSESTREAM
20
47
#include "ieee754io.h"
21
48
 
22
49
static void get_mbg_tzname P((unsigned char **, char *));
23
 
static void mbg_time_status_str P((unsigned char **, unsigned int));
 
50
static void mbg_time_status_str P((char **, unsigned int, int));
24
51
 
25
52
#if 0                           /* no actual floats on Meinberg binary interface */
26
53
static offsets_t mbg_float  = { 1, 0, 3, 2, 0, 0, 0, 0 }; /* byte order for meinberg floats */
181
208
 
182
209
static void
183
210
mbg_time_status_str(
184
 
        unsigned char **buffpp,
185
 
        unsigned int status
 
211
        char **buffpp,
 
212
        unsigned int status,
 
213
        int size
186
214
        )
187
215
{
188
 
  static struct state
189
 
    {
190
 
      int         flag;         /* bit flag */
191
 
      const char *string;       /* bit name */
192
 
    } states[] =
193
 
    {
194
 
      { TM_UTC,    "UTC CORR" },
195
 
      { TM_LOCAL,  "LOCAL TIME" },
196
 
      { TM_DL_ANN, "DST WARN" },
197
 
      { TM_DL_ENB, "DST" },
198
 
      { TM_LS_ANN, "LEAP WARN" },
199
 
      { TM_LS_ENB, "LEAP SEC" },
200
 
      { 0, "" }
201
 
    };
 
216
        static struct state
 
217
        {
 
218
                int         flag;               /* bit flag */
 
219
                const char *string;     /* bit name */
 
220
        } states[] =
 
221
                  {
 
222
                          { TM_UTC,    "UTC CORR" },
 
223
                          { TM_LOCAL,  "LOCAL TIME" },
 
224
                          { TM_DL_ANN, "DST WARN" },
 
225
                          { TM_DL_ENB, "DST" },
 
226
                          { TM_LS_ANN, "LEAP WARN" },
 
227
                          { TM_LS_ENB, "LEAP SEC" },
 
228
                          { 0, "" }
 
229
                  };
202
230
 
203
 
  if (status)
204
 
    {
205
 
      unsigned char *p;
206
 
      struct state *s;
 
231
        if (status)
 
232
        {
 
233
                char *start, *p;
 
234
                struct state *s;
207
235
        
208
 
      p = *buffpp;
 
236
                start = p = *buffpp;
209
237
 
210
 
      for (s = states; s->flag; s++)
211
 
        {
212
 
          if (s->flag & status)
213
 
            {
214
 
              if (p != *buffpp)
 
238
                for (s = states; s->flag; s++)
215
239
                {
216
 
                  *p++ = ',';
217
 
                  *p++ = ' ';
 
240
                        if (s->flag & status)
 
241
                        {
 
242
                                if (p != *buffpp)
 
243
                                {
 
244
                                        strncpy(p, ", ", size - (p - start));
 
245
                                        p += 2;
 
246
                                }
 
247
                                strncpy(p, s->string, size - (p - start));
 
248
                                p += strlen(p);
 
249
                        }
218
250
                }
219
 
              strcpy((char *)p, s->string);
220
 
              p += strlen((char *)p);
221
 
            }
 
251
                *buffpp = p;
222
252
        }
223
 
      *buffpp = p;
224
 
    }
225
253
}
226
254
      
227
255
void
228
256
mbg_tm_str(
229
 
        unsigned char **buffpp,
230
 
        TM *tmp
 
257
        char **buffpp,
 
258
        TM *tmp,
 
259
        int size
231
260
        )
232
261
{
233
 
  sprintf((char *)*buffpp, "%04d-%02d-%02d %02d:%02d:%02d.%07ld (%c%02d%02d) ",
234
 
          tmp->year, tmp->month, tmp->mday,
235
 
          tmp->hour, tmp->minute, tmp->second, tmp->frac,
236
 
          (tmp->offs_from_utc < 0) ? '-' : '+',
237
 
          abs(tmp->offs_from_utc) / 3600,
238
 
          (abs(tmp->offs_from_utc) / 60) % 60);
239
 
  *buffpp += strlen((char *)*buffpp);
240
 
  mbg_time_status_str(buffpp, tmp->status);
 
262
        char *s = *buffpp;
 
263
 
 
264
        snprintf(*buffpp, size, "%04d-%02d-%02d %02d:%02d:%02d.%07ld (%c%02d%02d) ",
 
265
                 tmp->year, tmp->month, tmp->mday,
 
266
                 tmp->hour, tmp->minute, tmp->second, tmp->frac,
 
267
                 (tmp->offs_from_utc < 0) ? '-' : '+',
 
268
                 abs(tmp->offs_from_utc) / 3600,
 
269
                 (abs(tmp->offs_from_utc) / 60) % 60);
 
270
        *buffpp += strlen(*buffpp);
 
271
 
 
272
        mbg_time_status_str(buffpp, tmp->status, size - (*buffpp - s));
241
273
}
242
274
 
243
275
void
244
276
mbg_tgps_str(
245
 
        unsigned char **buffpp,
246
 
        T_GPS *tgpsp
 
277
        char **buffpp,
 
278
        T_GPS *tgpsp,
 
279
        int size
247
280
        )
248
281
{
249
 
  sprintf((char *)*buffpp, "week %d + %ld days + %ld.%07ld sec",
250
 
          tgpsp->wn, tgpsp->sec / 86400,
251
 
          tgpsp->sec % 86400, tgpsp->tick);
252
 
  *buffpp += strlen((char *)*buffpp);
 
282
        snprintf(*buffpp, size, "week %d + %ld days + %ld.%07ld sec",
 
283
                 tgpsp->wn, tgpsp->sec / 86400,
 
284
                 tgpsp->sec % 86400, tgpsp->tick);
 
285
        *buffpp += strlen(*buffpp);
253
286
}
254
287
 
255
288
void
475
508
 
476
509
/*
477
510
 * data_mbg.c,v
 
511
 * Revision 4.8  2006/06/22 18:40:01  kardel
 
512
 * clean up signedness (gcc 4)
 
513
 *
 
514
 * Revision 4.7  2005/10/07 22:11:10  kardel
 
515
 * bounded buffer implementation
 
516
 *
 
517
 * Revision 4.6.2.1  2005/09/25 10:23:06  kardel
 
518
 * support bounded buffers
 
519
 *
 
520
 * Revision 4.6  2005/04/16 17:32:10  kardel
 
521
 * update copyright
 
522
 *
 
523
 * Revision 4.5  2004/11/14 15:29:41  kardel
 
524
 * support PPSAPI, upgrade Copyright to Berkeley style
 
525
 *
478
526
 * Revision 4.3  1999/02/21 12:17:42  kardel
479
527
 * 4.91f reconcilation
480
528
 *