diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-06-12 22:01:49 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-06-12 22:01:49 +0000 |
commit | 6ee2ce25363acc1c2f567d3b05788d625a28b989 (patch) | |
tree | 38a15adf1dcddaf463d455cb37655466ee22166e | |
parent | 711f136f3c77e21c0274c2a569f1854c28cb7385 (diff) | |
download | libextractor-6ee2ce25363acc1c2f567d3b05788d625a28b989.tar.gz libextractor-6ee2ce25363acc1c2f567d3b05788d625a28b989.zip |
style
-rw-r--r-- | src/common/convert.c | 2 | ||||
-rw-r--r-- | src/main/extract.c | 22 | ||||
-rw-r--r-- | src/main/extractor.c | 6 | ||||
-rw-r--r-- | src/main/extractor_print.c | 6 | ||||
-rw-r--r-- | src/main/iconv.c | 4 | ||||
-rw-r--r-- | src/plugins/deb_extractor.c | 5 | ||||
-rw-r--r-- | src/plugins/real_extractor.c | 179 |
7 files changed, 135 insertions, 89 deletions
diff --git a/src/common/convert.c b/src/common/convert.c index b139261..e4d8fea 100644 --- a/src/common/convert.c +++ b/src/common/convert.c | |||
@@ -45,6 +45,8 @@ EXTRACTOR_common_convert_to_utf8 (const char *input, size_t len, const char *cha | |||
45 | cd = iconv_open ("UTF-8", charset); | 45 | cd = iconv_open ("UTF-8", charset); |
46 | if (cd == (iconv_t) - 1) | 46 | if (cd == (iconv_t) - 1) |
47 | return strdup (i); | 47 | return strdup (i); |
48 | if (len > 1024 * 1024) | ||
49 | return NULL; /* too big for meta data */ | ||
48 | tmpSize = 3 * len + 4; | 50 | tmpSize = 3 * len + 4; |
49 | tmp = malloc (tmpSize); | 51 | tmp = malloc (tmpSize); |
50 | if (tmp == NULL) | 52 | if (tmp == NULL) |
diff --git a/src/main/extract.c b/src/main/extract.c index 8558548..5f6fa4c 100644 --- a/src/main/extract.c +++ b/src/main/extract.c | |||
@@ -91,7 +91,7 @@ static void formatHelp(const char * general, | |||
91 | int j; | 91 | int j; |
92 | int ml; | 92 | int ml; |
93 | int p; | 93 | int p; |
94 | char * scp; | 94 | char scp[80]; |
95 | const char * trans; | 95 | const char * trans; |
96 | 96 | ||
97 | printf(_("Usage: %s\n%s\n\n"), | 97 | printf(_("Usage: %s\n%s\n\n"), |
@@ -129,7 +129,6 @@ static void formatHelp(const char * general, | |||
129 | while (ml - p > 78 - slen) { | 129 | while (ml - p > 78 - slen) { |
130 | for (j=p+78-slen;j>p;j--) { | 130 | for (j=p+78-slen;j>p;j--) { |
131 | if (isspace( (unsigned char) trans[j])) { | 131 | if (isspace( (unsigned char) trans[j])) { |
132 | scp = malloc(j-p+1); | ||
133 | memcpy(scp, | 132 | memcpy(scp, |
134 | &trans[p], | 133 | &trans[p], |
135 | j-p); | 134 | j-p); |
@@ -138,14 +137,12 @@ static void formatHelp(const char * general, | |||
138 | scp, | 137 | scp, |
139 | BORDER+2, | 138 | BORDER+2, |
140 | ""); | 139 | ""); |
141 | free(scp); | ||
142 | p = j+1; | 140 | p = j+1; |
143 | slen = BORDER+2; | 141 | slen = BORDER+2; |
144 | goto OUTER; | 142 | goto OUTER; |
145 | } | 143 | } |
146 | } | 144 | } |
147 | /* could not find space to break line */ | 145 | /* could not find space to break line */ |
148 | scp = malloc(78 - slen + 1); | ||
149 | memcpy(scp, | 146 | memcpy(scp, |
150 | &trans[p], | 147 | &trans[p], |
151 | 78 - slen); | 148 | 78 - slen); |
@@ -154,7 +151,6 @@ static void formatHelp(const char * general, | |||
154 | scp, | 151 | scp, |
155 | BORDER+2, | 152 | BORDER+2, |
156 | ""); | 153 | ""); |
157 | free(scp); | ||
158 | slen = BORDER+2; | 154 | slen = BORDER+2; |
159 | p = p + 78 - slen; | 155 | p = p + 78 - slen; |
160 | } | 156 | } |
@@ -230,6 +226,7 @@ print_selected_keywords (void *cls, | |||
230 | char * keyword; | 226 | char * keyword; |
231 | iconv_t cd; | 227 | iconv_t cd; |
232 | const char *stype; | 228 | const char *stype; |
229 | const char *mt; | ||
233 | 230 | ||
234 | if (print[type] != YES) | 231 | if (print[type] != YES) |
235 | return 0; | 232 | return 0; |
@@ -237,7 +234,8 @@ print_selected_keywords (void *cls, | |||
237 | fprintf (stdout, | 234 | fprintf (stdout, |
238 | _("Found by `%s' plugin:\n"), | 235 | _("Found by `%s' plugin:\n"), |
239 | plugin_name); | 236 | plugin_name); |
240 | stype = gettext(EXTRACTOR_metatype_to_string(type)); | 237 | mt = EXTRACTOR_metatype_to_string(type); |
238 | stype = (mt == NULL) ? _("unknown") : gettext(mt); | ||
241 | switch (format) | 239 | switch (format) |
242 | { | 240 | { |
243 | case EXTRACTOR_METAFORMAT_UNKNOWN: | 241 | case EXTRACTOR_METAFORMAT_UNKNOWN: |
@@ -312,9 +310,13 @@ print_selected_keywords_grep_friendly (void *cls, | |||
312 | { | 310 | { |
313 | char * keyword; | 311 | char * keyword; |
314 | iconv_t cd; | 312 | iconv_t cd; |
313 | const char *mt; | ||
315 | 314 | ||
316 | if (print[type] != YES) | 315 | if (print[type] != YES) |
317 | return 0; | 316 | return 0; |
317 | mt = EXTRACTOR_metatype_to_string(type); | ||
318 | if (mt == NULL) | ||
319 | mt = gettext_noop ("unknown"); | ||
318 | switch (format) | 320 | switch (format) |
319 | { | 321 | { |
320 | case EXTRACTOR_METAFORMAT_UNKNOWN: | 322 | case EXTRACTOR_METAFORMAT_UNKNOWN: |
@@ -323,7 +325,7 @@ print_selected_keywords_grep_friendly (void *cls, | |||
323 | if (verbose > 1) | 325 | if (verbose > 1) |
324 | fprintf (stdout, | 326 | fprintf (stdout, |
325 | "%s: ", | 327 | "%s: ", |
326 | gettext(EXTRACTOR_metatype_to_string(type))); | 328 | gettext(mt)); |
327 | cd = iconv_open(nl_langinfo(CODESET), "UTF-8"); | 329 | cd = iconv_open(nl_langinfo(CODESET), "UTF-8"); |
328 | if (cd != (iconv_t) -1) | 330 | if (cd != (iconv_t) -1) |
329 | keyword = iconv_helper(cd, | 331 | keyword = iconv_helper(cd, |
@@ -333,7 +335,7 @@ print_selected_keywords_grep_friendly (void *cls, | |||
333 | if (keyword != NULL) | 335 | if (keyword != NULL) |
334 | { | 336 | { |
335 | fprintf (stdout, | 337 | fprintf (stdout, |
336 | "'%s' ", | 338 | "`%s' ", |
337 | keyword); | 339 | keyword); |
338 | free(keyword); | 340 | free(keyword); |
339 | } | 341 | } |
@@ -346,9 +348,9 @@ print_selected_keywords_grep_friendly (void *cls, | |||
346 | if (verbose > 1) | 348 | if (verbose > 1) |
347 | fprintf (stdout, | 349 | fprintf (stdout, |
348 | "%s ", | 350 | "%s ", |
349 | gettext(EXTRACTOR_metatype_to_string(type))); | 351 | gettext(mt)); |
350 | fprintf (stdout, | 352 | fprintf (stdout, |
351 | "'%s'", | 353 | "`%s'", |
352 | data); | 354 | data); |
353 | break; | 355 | break; |
354 | default: | 356 | default: |
diff --git a/src/main/extractor.c b/src/main/extractor.c index 66bfaba..51f9aa4 100644 --- a/src/main/extractor.c +++ b/src/main/extractor.c | |||
@@ -1220,6 +1220,12 @@ process_requests (struct EXTRACTOR_PluginList *plugin, | |||
1220 | 1220 | ||
1221 | memset (&hdr, 0, sizeof (hdr)); | 1221 | memset (&hdr, 0, sizeof (hdr)); |
1222 | fin = fdopen (in, "r"); | 1222 | fin = fdopen (in, "r"); |
1223 | if (fin == NULL) | ||
1224 | { | ||
1225 | close (in); | ||
1226 | close (out); | ||
1227 | return; | ||
1228 | } | ||
1223 | while (NULL != fgets (hfn, sizeof(hfn), fin)) | 1229 | while (NULL != fgets (hfn, sizeof(hfn), fin)) |
1224 | { | 1230 | { |
1225 | if (strlen (hfn) <= 1) | 1231 | if (strlen (hfn) <= 1) |
diff --git a/src/main/extractor_print.c b/src/main/extractor_print.c index e496b70..6ce619c 100644 --- a/src/main/extractor_print.c +++ b/src/main/extractor_print.c | |||
@@ -51,6 +51,7 @@ EXTRACTOR_meta_data_print(void * handle, | |||
51 | iconv_t cd; | 51 | iconv_t cd; |
52 | char * buf; | 52 | char * buf; |
53 | int ret; | 53 | int ret; |
54 | const char *mt; | ||
54 | 55 | ||
55 | if (format != EXTRACTOR_METAFORMAT_UTF8) | 56 | if (format != EXTRACTOR_METAFORMAT_UTF8) |
56 | return 0; | 57 | return 0; |
@@ -61,10 +62,11 @@ EXTRACTOR_meta_data_print(void * handle, | |||
61 | buf = iconv_helper(cd, data); | 62 | buf = iconv_helper(cd, data); |
62 | if (buf != NULL) | 63 | if (buf != NULL) |
63 | { | 64 | { |
65 | mt = EXTRACTOR_metatype_to_string (type); | ||
64 | ret = fprintf(handle, | 66 | ret = fprintf(handle, |
65 | "%s - %s\n", | 67 | "%s - %s\n", |
66 | dgettext ("libextractor", | 68 | (mt == NULL) ? _("unknown") : dgettext ("libextractor", |
67 | EXTRACTOR_metatype_to_string (type)), | 69 | mt), |
68 | buf); | 70 | buf); |
69 | free(buf); | 71 | free(buf); |
70 | } | 72 | } |
diff --git a/src/main/iconv.c b/src/main/iconv.c index 179cf89..fac6d21 100644 --- a/src/main/iconv.c +++ b/src/main/iconv.c | |||
@@ -37,7 +37,9 @@ iconv_helper(iconv_t cd, | |||
37 | iconv(cd, NULL, NULL, NULL, NULL); | 37 | iconv(cd, NULL, NULL, NULL, NULL); |
38 | 38 | ||
39 | inSize = strlen(in); | 39 | inSize = strlen(in); |
40 | outSize = 4 * strlen(in) + 2; | 40 | if (inSize > 1024 * 1024) |
41 | return NULL; /* too big to be meta data */ | ||
42 | outSize = 4 * inSize + 2; | ||
41 | outLeft = outSize - 2; /* make sure we have 2 0-terminations! */ | 43 | outLeft = outSize - 2; /* make sure we have 2 0-terminations! */ |
42 | buf = malloc(outSize); | 44 | buf = malloc(outSize); |
43 | if (buf == NULL) | 45 | if (buf == NULL) |
diff --git a/src/plugins/deb_extractor.c b/src/plugins/deb_extractor.c index 09a5a8e..b998b36 100644 --- a/src/plugins/deb_extractor.c +++ b/src/plugins/deb_extractor.c | |||
@@ -223,10 +223,15 @@ processControlTar (const char *data, | |||
223 | } | 223 | } |
224 | 224 | ||
225 | #define MAX_CONTROL_SIZE (1024 * 1024) | 225 | #define MAX_CONTROL_SIZE (1024 * 1024) |
226 | #ifndef SIZE_MAX | ||
227 | #define SIZE_MAX ((size_t)-1) | ||
228 | #endif | ||
226 | 229 | ||
227 | static voidpf | 230 | static voidpf |
228 | Emalloc (voidpf opaque, uInt items, uInt size) | 231 | Emalloc (voidpf opaque, uInt items, uInt size) |
229 | { | 232 | { |
233 | if (SIZE_MAX / size <= items) | ||
234 | return NULL; | ||
230 | return malloc (size * items); | 235 | return malloc (size * items); |
231 | } | 236 | } |
232 | 237 | ||
diff --git a/src/plugins/real_extractor.c b/src/plugins/real_extractor.c index c6089af..d96dd6c 100644 --- a/src/plugins/real_extractor.c +++ b/src/plugins/real_extractor.c | |||
@@ -162,63 +162,76 @@ processContentDescription (const Content_Description * prop, | |||
162 | + sizeof (Content_Description)) | 162 | + sizeof (Content_Description)) |
163 | return 0; | 163 | return 0; |
164 | 164 | ||
165 | ret = 0; | ||
165 | title = malloc (title_len + 1); | 166 | title = malloc (title_len + 1); |
166 | memcpy (title, &prop->data[0], title_len); | 167 | if (title != NULL) |
167 | title[title_len] = '\0'; | 168 | { |
168 | ret = proc (proc_cls, | 169 | memcpy (title, &prop->data[0], title_len); |
169 | "real", | 170 | title[title_len] = '\0'; |
170 | EXTRACTOR_METATYPE_TITLE, | 171 | ret = proc (proc_cls, |
171 | EXTRACTOR_METAFORMAT_UTF8, | 172 | "real", |
172 | "text/plain", | 173 | EXTRACTOR_METATYPE_TITLE, |
173 | title, | 174 | EXTRACTOR_METAFORMAT_UTF8, |
174 | strlen (title)+1); | 175 | "text/plain", |
175 | free (title); | 176 | title, |
177 | strlen (title)+1); | ||
178 | free (title); | ||
179 | } | ||
176 | if (ret != 0) | 180 | if (ret != 0) |
177 | return ret; | 181 | return ret; |
178 | 182 | ||
179 | author = malloc (author_len + 1); | 183 | author = malloc (author_len + 1); |
180 | memcpy (author, &prop->data[title_len + sizeof (UINT16)], author_len); | 184 | if (author != NULL) |
181 | author[author_len] = '\0'; | 185 | { |
182 | ret = proc (proc_cls, | 186 | memcpy (author, &prop->data[title_len + sizeof (UINT16)], author_len); |
183 | "real", | 187 | author[author_len] = '\0'; |
184 | EXTRACTOR_METATYPE_AUTHOR_NAME, | 188 | ret = proc (proc_cls, |
185 | EXTRACTOR_METAFORMAT_UTF8, | 189 | "real", |
186 | "text/plain", | 190 | EXTRACTOR_METATYPE_AUTHOR_NAME, |
187 | author, | 191 | EXTRACTOR_METAFORMAT_UTF8, |
188 | strlen (author)+1); | 192 | "text/plain", |
189 | free (author); | 193 | author, |
194 | strlen (author)+1); | ||
195 | free (author); | ||
196 | } | ||
190 | if (ret != 0) | 197 | if (ret != 0) |
191 | return ret; | 198 | return ret; |
192 | 199 | ||
193 | copyright = malloc (copyright_len + 1); | 200 | copyright = malloc (copyright_len + 1); |
194 | memcpy (copyright, | 201 | if (copyright != NULL) |
195 | &prop->data[title_len + sizeof (UINT16) * 2 + author_len], | 202 | { |
196 | copyright_len); | 203 | memcpy (copyright, |
197 | copyright[copyright_len] = '\0'; | 204 | &prop->data[title_len + sizeof (UINT16) * 2 + author_len], |
198 | ret = proc (proc_cls, | 205 | copyright_len); |
199 | "real", | 206 | copyright[copyright_len] = '\0'; |
200 | EXTRACTOR_METATYPE_COPYRIGHT, | 207 | ret = proc (proc_cls, |
201 | EXTRACTOR_METAFORMAT_UTF8, | 208 | "real", |
202 | "text/plain", | 209 | EXTRACTOR_METATYPE_COPYRIGHT, |
203 | copyright, | 210 | EXTRACTOR_METAFORMAT_UTF8, |
204 | strlen (copyright)+1); | 211 | "text/plain", |
205 | free (copyright); | 212 | copyright, |
213 | strlen (copyright)+1); | ||
214 | free (copyright); | ||
215 | } | ||
206 | if (ret != 0) | 216 | if (ret != 0) |
207 | return ret; | 217 | return ret; |
208 | 218 | ||
209 | comment = malloc (comment_len + 1); | 219 | comment = malloc (comment_len + 1); |
210 | memcpy (comment, | 220 | if (comment != NULL) |
211 | &prop->data[title_len + sizeof (UINT16) * 3 + author_len + | 221 | { |
212 | copyright_len], comment_len); | 222 | memcpy (comment, |
213 | comment[comment_len] = '\0'; | 223 | &prop->data[title_len + sizeof (UINT16) * 3 + author_len + |
214 | ret = proc (proc_cls, | 224 | copyright_len], comment_len); |
215 | "real", | 225 | comment[comment_len] = '\0'; |
216 | EXTRACTOR_METATYPE_COMMENT, | 226 | ret = proc (proc_cls, |
217 | EXTRACTOR_METAFORMAT_UTF8, | 227 | "real", |
218 | "text/plain", | 228 | EXTRACTOR_METATYPE_COMMENT, |
219 | comment, | 229 | EXTRACTOR_METAFORMAT_UTF8, |
220 | strlen (comment)+1); | 230 | "text/plain", |
221 | free (comment); | 231 | comment, |
232 | strlen (comment)+1); | ||
233 | free (comment); | ||
234 | } | ||
222 | if (ret != 0) | 235 | if (ret != 0) |
223 | return ret; | 236 | return ret; |
224 | return 0; | 237 | return 0; |
@@ -263,6 +276,8 @@ stndup (const char *str, size_t n) | |||
263 | { | 276 | { |
264 | char *tmp; | 277 | char *tmp; |
265 | tmp = malloc (n + 1); | 278 | tmp = malloc (n + 1); |
279 | if (tmp == NULL) | ||
280 | return NULL; | ||
266 | tmp[n] = '\0'; | 281 | tmp[n] = '\0'; |
267 | memcpy (tmp, str, n); | 282 | memcpy (tmp, str, n); |
268 | return tmp; | 283 | return tmp; |
@@ -321,50 +336,62 @@ EXTRACTOR_real_extract (const unsigned char *data, | |||
321 | if ( (tlen > 0) && (ret == 0) ) | 336 | if ( (tlen > 0) && (ret == 0) ) |
322 | { | 337 | { |
323 | x = stndup ((const char *) &data[17 + RAFF4_HDR_SIZE], tlen); | 338 | x = stndup ((const char *) &data[17 + RAFF4_HDR_SIZE], tlen); |
324 | ret = proc (proc_cls, | 339 | if (x != NULL) |
325 | "real", | 340 | { |
326 | EXTRACTOR_METATYPE_MIMETYPE, | 341 | ret = proc (proc_cls, |
327 | EXTRACTOR_METAFORMAT_UTF8, | 342 | "real", |
328 | "text/plain", | 343 | EXTRACTOR_METATYPE_MIMETYPE, |
329 | x, | 344 | EXTRACTOR_METAFORMAT_UTF8, |
330 | strlen (x)+1); | 345 | "text/plain", |
331 | free (x); | 346 | x, |
347 | strlen (x)+1); | ||
348 | free (x); | ||
349 | } | ||
332 | } | 350 | } |
333 | if ( (alen > 0) && (ret == 0) ) | 351 | if ( (alen > 0) && (ret == 0) ) |
334 | { | 352 | { |
335 | x = stndup ((const char *) &data[18 + RAFF4_HDR_SIZE + tlen], alen); | 353 | x = stndup ((const char *) &data[18 + RAFF4_HDR_SIZE + tlen], alen); |
336 | ret = proc (proc_cls, | 354 | if (x != NULL) |
337 | "real", | 355 | { |
338 | EXTRACTOR_METATYPE_MIMETYPE, | 356 | ret = proc (proc_cls, |
339 | EXTRACTOR_METAFORMAT_UTF8, | 357 | "real", |
340 | "text/plain", | 358 | EXTRACTOR_METATYPE_MIMETYPE, |
341 | x, | 359 | EXTRACTOR_METAFORMAT_UTF8, |
342 | strlen (x)+1); | 360 | "text/plain", |
343 | free (x); | 361 | x, |
362 | strlen (x)+1); | ||
363 | free (x); | ||
364 | } | ||
344 | } | 365 | } |
345 | if ( (clen > 0) && (ret == 0) ) | 366 | if ( (clen > 0) && (ret == 0) ) |
346 | { | 367 | { |
347 | x = stndup ((const char *) &data[19 + RAFF4_HDR_SIZE + tlen + alen], clen); | 368 | x = stndup ((const char *) &data[19 + RAFF4_HDR_SIZE + tlen + alen], clen); |
348 | ret = proc (proc_cls, | 369 | if (x != NULL) |
349 | "real", | 370 | { |
350 | EXTRACTOR_METATYPE_MIMETYPE, | 371 | ret = proc (proc_cls, |
351 | EXTRACTOR_METAFORMAT_UTF8, | 372 | "real", |
352 | "text/plain", | 373 | EXTRACTOR_METATYPE_MIMETYPE, |
353 | x, | 374 | EXTRACTOR_METAFORMAT_UTF8, |
354 | strlen (x)+1); | 375 | "text/plain", |
355 | free (x); | 376 | x, |
377 | strlen (x)+1); | ||
378 | free (x); | ||
379 | } | ||
356 | } | 380 | } |
357 | if ( (aplen > 0) && (ret == 0) ) | 381 | if ( (aplen > 0) && (ret == 0) ) |
358 | { | 382 | { |
359 | x = stndup ((const char *) &data[20 + RAFF4_HDR_SIZE + tlen + alen + clen], aplen); | 383 | x = stndup ((const char *) &data[20 + RAFF4_HDR_SIZE + tlen + alen + clen], aplen); |
360 | ret = proc (proc_cls, | 384 | if (x != NULL) |
361 | "real", | 385 | { |
362 | EXTRACTOR_METATYPE_MIMETYPE, | 386 | ret = proc (proc_cls, |
363 | EXTRACTOR_METAFORMAT_UTF8, | 387 | "real", |
364 | "text/plain", | 388 | EXTRACTOR_METATYPE_MIMETYPE, |
365 | x, | 389 | EXTRACTOR_METAFORMAT_UTF8, |
366 | strlen (x)+1); | 390 | "text/plain", |
367 | free (x); | 391 | x, |
392 | strlen (x)+1); | ||
393 | free (x); | ||
394 | } | ||
368 | } | 395 | } |
369 | return ret; | 396 | return ret; |
370 | } | 397 | } |