1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
diff -Nrup aspell-0.50.5.orig/prog/compress.c aspell-0.50.5/prog/compress.c
--- aspell-0.50.5.orig/prog/compress.c 2002-08-31 14:51:11.000000000 -0400
+++ aspell-0.50.5/prog/compress.c 2004-08-15 15:07:26.000000000 -0400
@@ -28,24 +28,27 @@
#endif
+#define BUFSIZE 256
+
void usage ()
{
fputs("Compresses or uncompresses sorted word lists.\n" , stderr);
fputs("For best result the locale should be set to C\n" , stderr);
fputs("before sorting by setting the environmental\n" , stderr);
fputs("variable LANG to \"C\" before sorting.\n" , stderr);
- fputs("Copyright 2001 by Kevin Atkinson.\n" , stderr);
+ fputs("Copyright 2001-2004 by Kevin Atkinson.\n" , stderr);
fputs("Usage: word-list-compress c[ompress]|d[ecompress]\n" , stderr);
}
-static int get_word(FILE * in, char * w)
+static int get_word(FILE * in, char * w, size_t bufsize)
{
int c;
while (c = getc(in), c != EOF && c <= 32);
if (c == EOF) return 0;
do {
*w++ = (char)(c);
- } while (c = getc(in), c != EOF && c > 32);
+ --bufsize;
+ } while (c = getc(in), c != EOF && c > 32 && bufsize > 1);
*w = '\0';
ungetc(c, in);
if (c == EOF) return 0;
@@ -61,15 +64,15 @@ int main (int argc, const char *argv[])
} else if (argv[1][0] == 'c') {
- char s1[256];
- char s2[256];
+ char s1[BUFSIZE];
+ char s2[BUFSIZE];
char * prev = s2;
char * cur = s1;
*prev = '\0';
SETBIN (stdout);
- while (get_word(stdin, cur)) {
+ while (get_word(stdin, cur, BUFSIZE)) {
int i = 0;
/* get the length of the prefix */
while (prev[i] != '\0' && cur[i] != '\0' && prev[i] == cur[i])
@@ -99,9 +102,10 @@ int main (int argc, const char *argv[])
while (i != -1 ) {
if (i == 0)
i = getc(stdin);
- --i;
- while ((c = getc(stdin)) > 32)
+ --i; if (i < 0) goto error;
+ while ((c = getc(stdin)) > 32 && i < BUFSIZE)
cur[i++] = (char)c;
+ if (i >= BUFSIZE) goto error;
cur[i] = '\0';
fputs(cur, stdout);
putc('\n', stdout);
@@ -109,6 +113,10 @@ int main (int argc, const char *argv[])
}
return 0;
+error:
+ fputs("ERROR: Corrupt Input.\n", stderr);
+ return 2;
+
} else {
usage();
|