~ubuntu-branches/ubuntu/hardy/openswan/hardy-updates

« back to all changes in this revision

Viewing changes to debian/openswan-modules-source-build/modules/openswan/linux/lib/libfreeswan/atoasr.c

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayrhofer
  • Date: 2005-01-27 16:10:11 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050127161011-idgybmyz3vwhpfiq
Tags: 2.3.0-2
Urgency HIGH due to security issue and problems with build-deps in sarge.
* Fix the security issue. Please see
  http://www.idefense.com/application/poi/display?id=190&
      type=vulnerabilities&flashstatus=false
  for more details. Thanks to Martin Schulze for informing me about
  this issue.
  Closes: #292458: Openswan XAUTH/PAM Buffer Overflow Vulnerability
* Added a Build-Dependency to lynx.
  Closes: #291143: openswan: FTBFS: Missing build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * convert from ASCII form of address/subnet/range to binary
3
 
 * Copyright (C) 1998, 1999  Henry Spencer.
4
 
 * 
5
 
 * This library is free software; you can redistribute it and/or modify it
6
 
 * under the terms of the GNU Library General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or (at your
8
 
 * option) any later version.  See <http://www.fsf.org/copyleft/lgpl.txt>.
9
 
 * 
10
 
 * This library is distributed in the hope that it will be useful, but
11
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
 
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
13
 
 * License for more details.
14
 
 *
15
 
 * RCSID $Id: atoasr.c,v 1.8.10.1 2004/03/21 05:23:31 mcr Exp $
16
 
 */
17
 
#include "internal.h"
18
 
#include "openswan.h"
19
 
 
20
 
/*
21
 
 - atoasr - convert ASCII to address, subnet, or range
22
 
 */
23
 
const char *                    /* NULL for success, else string literal */
24
 
atoasr(src, srclen, typep, addrsp)
25
 
const char *src;
26
 
size_t srclen;                  /* 0 means "apply strlen" */
27
 
char *typep;                    /* return type code:  'a', 's', 'r' */
28
 
struct in_addr addrsp[2];
29
 
{
30
 
        const char *punct;
31
 
        const char *stop;
32
 
        const char *oops;
33
 
 
34
 
        if (srclen == 0)
35
 
                srclen = strlen(src);
36
 
        if (srclen == 0)
37
 
                return "empty string";
38
 
 
39
 
        /* subnet is easy to spot */
40
 
        punct = memchr(src, '/', srclen);
41
 
        if (punct != NULL) {
42
 
                *typep = 's';
43
 
                return atosubnet(src, srclen, &addrsp[0], &addrsp[1]);
44
 
        }
45
 
 
46
 
        /* try for a range */
47
 
        stop = src + srclen;
48
 
        for (punct = src; (punct = memchr(punct, '.', stop - punct)) != NULL;
49
 
                                                                        punct++)
50
 
                if (stop - punct > 3 && *(punct+1) == '.' && *(punct+2) == '.')
51
 
                        break;                  /* NOTE BREAK OUT */
52
 
        if (punct == NULL) {
53
 
                /* didn't find the range delimiter, must be plain address */
54
 
                *typep = 'a';
55
 
                return atoaddr(src, srclen, &addrsp[0]);
56
 
        }
57
 
 
58
 
        /* looks like a range */
59
 
        *typep = 'r';
60
 
        if (stop - punct > 4 && *(punct+3) == '.')
61
 
                punct++;                /* first dot is trailing dot of name */
62
 
        oops = atoaddr(src, punct - src, &addrsp[0]);
63
 
        if (oops != NULL)
64
 
                return oops;
65
 
        oops = atoaddr(punct+3, stop - (punct+3), &addrsp[1]);
66
 
        if (oops != NULL)
67
 
                return oops;
68
 
        if (ntohl(addrsp[0].s_addr) > ntohl(addrsp[1].s_addr))
69
 
                return "invalid range, begin > end";
70
 
        return NULL;
71
 
}
72
 
 
73
 
 
74
 
 
75
 
#ifdef ATOASR_MAIN
76
 
 
77
 
#include <stdio.h>
78
 
#include <sys/socket.h>
79
 
#include <netinet/in.h>
80
 
#include <arpa/inet.h>
81
 
 
82
 
void regress(void);
83
 
 
84
 
int
85
 
main(int argc, char *argv[])
86
 
{
87
 
        struct in_addr a[2];
88
 
        char buf[100];
89
 
        const char *oops;
90
 
        size_t n;
91
 
        char type;
92
 
 
93
 
        if (argc < 2) {
94
 
                fprintf(stderr, "Usage: %s {addr|net/mask|begin...end|-r}\n",
95
 
                                                                argv[0]);
96
 
                exit(2);
97
 
        }
98
 
 
99
 
        if (strcmp(argv[1], "-r") == 0) {
100
 
                regress();
101
 
                fprintf(stderr, "regress() returned?!?\n");
102
 
                exit(1);
103
 
        }
104
 
 
105
 
        oops = atoasr(argv[1], 0, &type, a);
106
 
        if (oops != NULL) {
107
 
                fprintf(stderr, "%s: conversion failed: %s\n", argv[0], oops);
108
 
                exit(1);
109
 
        }
110
 
        switch (type) {
111
 
        case 'a':
112
 
                n = addrtoa(a[0], 0, buf, sizeof(buf));
113
 
                break;
114
 
        case 's':
115
 
                n = subnettoa(a[0], a[1], 0, buf, sizeof(buf));
116
 
                break;
117
 
        case 'r':
118
 
                n = rangetoa(a, 0, buf, sizeof(buf));
119
 
                break;
120
 
        default:
121
 
                fprintf(stderr, "%s: unknown type '%c'\n", argv[0], type);
122
 
                exit(1);
123
 
                break;
124
 
        }
125
 
        if (n > sizeof(buf)) {
126
 
                fprintf(stderr, "%s: reverse conversion of ", argv[0]);
127
 
                fprintf(stderr, "%s ", inet_ntoa(a[0]));
128
 
                fprintf(stderr, "%s", inet_ntoa(a[1]));
129
 
                fprintf(stderr, " failed: need %ld bytes, have only %ld\n",
130
 
                                                (long)n, (long)sizeof(buf));
131
 
                exit(1);
132
 
        }
133
 
        printf("%s\n", buf);
134
 
 
135
 
        exit(0);
136
 
}
137
 
 
138
 
struct rtab {
139
 
        char *input;
140
 
        char *output;                   /* NULL means error expected */
141
 
} rtab[] = {
142
 
        {"1.2.3.0",                     "1.2.3.0"},
143
 
        {"1.2.3.0/255.255.255.0",       "1.2.3.0/24"},
144
 
        {"1.2.3.0...1.2.3.5",           "1.2.3.0...1.2.3.5"},
145
 
        {"1.2.3.4.5",                   NULL},
146
 
        {"1.2.3.4/",                    NULL},
147
 
        {"1.2.3.4...",                  NULL},
148
 
        {"1.2.3.4....",                 NULL},
149
 
        {"localhost/32",                        "127.0.0.1/32"},
150
 
        {"localhost...127.0.0.3",       "127.0.0.1...127.0.0.3"},
151
 
        {"127.0.0.0...localhost",       "127.0.0.0...127.0.0.1"},
152
 
        {"127.0.0.3...localhost",       NULL},
153
 
        {NULL,                          NULL}
154
 
};
155
 
 
156
 
void
157
 
regress(void)
158
 
{
159
 
        struct rtab *r;
160
 
        int status = 0;
161
 
        struct in_addr a[2];
162
 
        char in[100];
163
 
        char buf[100];
164
 
        const char *oops;
165
 
        size_t n;
166
 
        char type;
167
 
 
168
 
        for (r = rtab; r->input != NULL; r++) {
169
 
                strcpy(in, r->input);
170
 
                oops = atoasr(in, 0, &type, a);
171
 
                if (oops != NULL && r->output == NULL)
172
 
                        {}              /* okay, error expected */
173
 
                else if (oops != NULL) {
174
 
                        printf("`%s' atoasr failed: %s\n", r->input, oops);
175
 
                        status = 1;
176
 
                } else if (r->output == NULL) {
177
 
                        printf("`%s' atoasr succeeded unexpectedly '%c'\n",
178
 
                                                        r->input, type);
179
 
                        status = 1;
180
 
                } else {
181
 
                        switch (type) {
182
 
                        case 'a':
183
 
                                n = addrtoa(a[0], 0, buf, sizeof(buf));
184
 
                                break;
185
 
                        case 's':
186
 
                                n = subnettoa(a[0], a[1], 0, buf, sizeof(buf));
187
 
                                break;
188
 
                        case 'r':
189
 
                                n = rangetoa(a, 0, buf, sizeof(buf));
190
 
                                break;
191
 
                        default:
192
 
                                fprintf(stderr, "`%s' unknown type '%c'\n",
193
 
                                                        r->input, type);
194
 
                                n = 0;
195
 
                                status = 1;
196
 
                                break;
197
 
                        }
198
 
                        if (n > sizeof(buf)) {
199
 
                                printf("`%s' '%c' reverse failed:  need %ld\n",
200
 
                                                r->input, type, (long)n);
201
 
                                status = 1;
202
 
                        } else if (n > 0 && strcmp(r->output, buf) != 0) {
203
 
                                printf("`%s' '%c' gave `%s', expected `%s'\n",
204
 
                                        r->input, type, buf, r->output);
205
 
                                status = 1;
206
 
                        }
207
 
                }
208
 
        }
209
 
        exit(status);
210
 
}
211
 
 
212
 
#endif /* ATOASR_MAIN */