aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-06-12 23:28:36 +0000
committerChristian Grothoff <christian@grothoff.org>2010-06-12 23:28:36 +0000
commit5e9a1a7e08cb7e116eddcd30f9bc528e0dc9ee96 (patch)
tree8a4c25e061ae5762d679957db38541f48018e39e
parent0b10d145926240dd86c1d70ff7f91258347a0d1c (diff)
downloadlibextractor-5e9a1a7e08cb7e116eddcd30f9bc528e0dc9ee96.tar.gz
libextractor-5e9a1a7e08cb7e116eddcd30f9bc528e0dc9ee96.zip
null checks and a few missing frees
-rw-r--r--src/plugins/deb_extractor.c9
-rw-r--r--src/plugins/html_extractor.c57
-rw-r--r--src/plugins/id3_extractor.c32
-rw-r--r--src/plugins/man_extractor.c4
-rw-r--r--src/plugins/nsfe_extractor.c46
-rw-r--r--src/plugins/tiff_extractor.c11
6 files changed, 99 insertions, 60 deletions
diff --git a/src/plugins/deb_extractor.c b/src/plugins/deb_extractor.c
index 706b54c..2bb90c5 100644
--- a/src/plugins/deb_extractor.c
+++ b/src/plugins/deb_extractor.c
@@ -40,6 +40,8 @@ stndup (const char *str, size_t n)
40{ 40{
41 char *tmp; 41 char *tmp;
42 tmp = malloc (n + 1); 42 tmp = malloc (n + 1);
43 if (tmp == NULL)
44 return NULL;
43 tmp[n] = '\0'; 45 tmp[n] = '\0';
44 memcpy (tmp, str, n); 46 memcpy (tmp, str, n);
45 return tmp; 47 return tmp;
@@ -114,12 +116,19 @@ processControl (const char *data,
114 if ((eol == colon) || (eol > size)) 116 if ((eol == colon) || (eol > size))
115 return 0; 117 return 0;
116 key = stndup (&data[pos], colon - pos); 118 key = stndup (&data[pos], colon - pos);
119 if (key == NULL)
120 return 0;
117 i = 0; 121 i = 0;
118 while (tmap[i].text != NULL) 122 while (tmap[i].text != NULL)
119 { 123 {
120 if (0 == strcmp (key, tmap[i].text)) 124 if (0 == strcmp (key, tmap[i].text))
121 { 125 {
122 val = stndup (&data[colon], eol - colon); 126 val = stndup (&data[colon], eol - colon);
127 if (val == NULL)
128 {
129 free (key);
130 return 0;
131 }
123 if (0 != proc (proc_cls, 132 if (0 != proc (proc_cls,
124 "deb", 133 "deb",
125 tmap[i].type, 134 tmap[i].type,
diff --git a/src/plugins/html_extractor.c b/src/plugins/html_extractor.c
index f7e367a..004d22a 100644
--- a/src/plugins/html_extractor.c
+++ b/src/plugins/html_extractor.c
@@ -339,26 +339,31 @@ EXTRACTOR_html_extract (const char *data,
339 (ret == 0) ) 339 (ret == 0) )
340 { 340 {
341 if (charset == NULL) 341 if (charset == NULL)
342 ret = proc (proc_cls,
343 "html",
344 tagmap[i].type,
345 EXTRACTOR_METAFORMAT_C_STRING,
346 "text/plain",
347 tmp,
348 strlen (tmp) + 1);
349 else
350 { 342 {
351 xtmp = EXTRACTOR_common_convert_to_utf8 (tmp,
352 strlen (tmp),
353 charset);
354 ret = proc (proc_cls, 343 ret = proc (proc_cls,
355 "html", 344 "html",
356 tagmap[i].type, 345 tagmap[i].type,
357 EXTRACTOR_METAFORMAT_UTF8, 346 EXTRACTOR_METAFORMAT_C_STRING,
358 "text/plain", 347 "text/plain",
359 xtmp, 348 tmp,
360 strlen (xtmp) + 1); 349 strlen (tmp) + 1);
361 free (xtmp); 350 }
351 else
352 {
353 xtmp = EXTRACTOR_common_convert_to_utf8 (tmp,
354 strlen (tmp),
355 charset);
356 if (xtmp != NULL)
357 {
358 ret = proc (proc_cls,
359 "html",
360 tagmap[i].type,
361 EXTRACTOR_METAFORMAT_UTF8,
362 "text/plain",
363 xtmp,
364 strlen (xtmp) + 1);
365 free (xtmp);
366 }
362 } 367 }
363 } 368 }
364 if (tmp != NULL) 369 if (tmp != NULL)
@@ -393,19 +398,23 @@ EXTRACTOR_html_extract (const char *data,
393 xtmp = EXTRACTOR_common_convert_to_utf8 (t->dataStart, 398 xtmp = EXTRACTOR_common_convert_to_utf8 (t->dataStart,
394 t->dataEnd - t->dataStart, 399 t->dataEnd - t->dataStart,
395 charset); 400 charset);
396 ret = proc (proc_cls, 401 if (xtmp != NULL)
397 "html", 402 {
398 EXTRACTOR_METATYPE_TITLE, 403 ret = proc (proc_cls,
399 EXTRACTOR_METAFORMAT_UTF8, 404 "html",
400 "text/plain", 405 EXTRACTOR_METATYPE_TITLE,
401 xtmp, 406 EXTRACTOR_METAFORMAT_UTF8,
402 strlen (xtmp) + 1); 407 "text/plain",
403 free (xtmp); 408 xtmp,
409 strlen (xtmp) + 1);
410 free (xtmp);
411 }
404 } 412 }
405 } 413 }
406 tags = t->next; 414 tags = t->next;
407 free (t); 415 free (t);
408 } 416 }
409 free (charset); 417 if (charset != NULL)
418 free (charset);
410 return ret; 419 return ret;
411} 420}
diff --git a/src/plugins/id3_extractor.c b/src/plugins/id3_extractor.c
index 4c89075..64d341c 100644
--- a/src/plugins/id3_extractor.c
+++ b/src/plugins/id3_extractor.c
@@ -202,6 +202,8 @@ static const char *const genre_names[] = {
202static void 202static void
203trim (char *k) 203trim (char *k)
204{ 204{
205 if (k == NULL)
206 return;
205 while ((strlen (k) > 0) && (isspace ((unsigned char) k[strlen (k) - 1]))) 207 while ((strlen (k) > 0) && (isspace ((unsigned char) k[strlen (k) - 1])))
206 k[strlen (k) - 1] = '\0'; 208 k[strlen (k) - 1] = '\0';
207} 209}
@@ -251,7 +253,7 @@ get_id3 (const char *data, size_t size, id3tag * id3)
251} 253}
252 254
253 255
254#define ADD(s,t) do { if (0 != (ret = proc (proc_cls, "id3", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1))) goto FINISH; } while (0) 256#define ADD(s,t) do { if ( (s != NULL) && (strlen(s) > 0) && (0 != (ret = proc (proc_cls, "id3", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1)))) goto FINISH; } while (0)
255 257
256 258
257const char * 259const char *
@@ -275,18 +277,12 @@ EXTRACTOR_id3_extract (const char *data,
275 ret = 0; 277 ret = 0;
276 if (OK != get_id3 (data, size, &info)) 278 if (OK != get_id3 (data, size, &info))
277 return 0; 279 return 0;
278 if (strlen (info.title) > 0) 280 ADD (info.title, EXTRACTOR_METATYPE_TITLE);
279 ADD (info.title, EXTRACTOR_METATYPE_TITLE); 281 ADD (info.artist, EXTRACTOR_METATYPE_ARTIST);
280 if (strlen (info.artist) > 0) 282 ADD (info.album, EXTRACTOR_METATYPE_ALBUM);
281 ADD (info.artist, EXTRACTOR_METATYPE_ARTIST); 283 ADD (info.year, EXTRACTOR_METATYPE_PUBLICATION_YEAR);
282 if (strlen (info.album) > 0) 284 ADD (info.genre, EXTRACTOR_METATYPE_GENRE);
283 ADD (info.album, EXTRACTOR_METATYPE_ALBUM); 285 ADD (info.comment, EXTRACTOR_METATYPE_COMMENT);
284 if (strlen (info.year) > 0)
285 ADD (info.year, EXTRACTOR_METATYPE_PUBLICATION_YEAR);
286 if (strlen (info.genre) > 0)
287 ADD (info.genre, EXTRACTOR_METATYPE_GENRE);
288 if (strlen (info.comment) > 0)
289 ADD (info.comment, EXTRACTOR_METATYPE_COMMENT);
290 if (info.track_number != 0) 286 if (info.track_number != 0)
291 { 287 {
292 snprintf(track, 288 snprintf(track,
@@ -294,11 +290,11 @@ EXTRACTOR_id3_extract (const char *data,
294 ADD (track, EXTRACTOR_METATYPE_TRACK_NUMBER); 290 ADD (track, EXTRACTOR_METATYPE_TRACK_NUMBER);
295 } 291 }
296FINISH: 292FINISH:
297 free (info.title); 293 if (info.title != NULL) free (info.title);
298 free (info.year); 294 if (info.year != NULL) free (info.year);
299 free (info.album); 295 if (info.album != NULL) free (info.album);
300 free (info.artist); 296 if (info.artist != NULL) free (info.artist);
301 free (info.comment); 297 if (info.comment != NULL) free (info.comment);
302 return ret; 298 return ret;
303} 299}
304 300
diff --git a/src/plugins/man_extractor.c b/src/plugins/man_extractor.c
index c6ecfc5..eeb40a8 100644
--- a/src/plugins/man_extractor.c
+++ b/src/plugins/man_extractor.c
@@ -27,6 +27,8 @@ stndup (const char *str, size_t n)
27{ 27{
28 char *tmp; 28 char *tmp;
29 tmp = malloc (n + 1); 29 tmp = malloc (n + 1);
30 if (tmp == NULL)
31 return NULL;
30 tmp[n] = '\0'; 32 tmp[n] = '\0';
31 memcpy (tmp, str, n); 33 memcpy (tmp, str, n);
32 return tmp; 34 return tmp;
@@ -53,6 +55,8 @@ addKeyword (enum EXTRACTOR_MetaType type,
53 keyword[strlen (keyword) - 1] = '\0'; 55 keyword[strlen (keyword) - 1] = '\0';
54 tmp = strdup (&keyword[1]); 56 tmp = strdup (&keyword[1]);
55 free (keyword); 57 free (keyword);
58 if (tmp == NULL)
59 return 0;
56 keyword = tmp; 60 keyword = tmp;
57 } 61 }
58 if (strlen (keyword) == 0) 62 if (strlen (keyword) == 0)
diff --git a/src/plugins/nsfe_extractor.c b/src/plugins/nsfe_extractor.c
index 1f3d35f..08c0509 100644
--- a/src/plugins/nsfe_extractor.c
+++ b/src/plugins/nsfe_extractor.c
@@ -84,6 +84,8 @@ nsfestring (const char *data, size_t size)
84 (data[length] != '\0') ) 84 (data[length] != '\0') )
85 length++; 85 length++;
86 s = malloc (length + 1); 86 s = malloc (length + 1);
87 if (s == NULL)
88 return NULL;
87 strncpy (s, data, length); 89 strncpy (s, data, length);
88 s[strlen (data)] = '\0'; 90 s[strlen (data)] = '\0';
89 return s; 91 return s;
@@ -157,8 +159,11 @@ libextractor_nsfe_tlbl_extract(const char *data,
157 for (left = size; left > 0; left -= length) 159 for (left = size; left > 0; left -= length)
158 { 160 {
159 title = nsfestring (&data[size - left], left); 161 title = nsfestring (&data[size - left], left);
160 length = strlen (title) + 1; 162 if (title != NULL)
161 ADDF (title, EXTRACTOR_METATYPE_TITLE); 163 {
164 length = strlen (title) + 1;
165 ADDF (title, EXTRACTOR_METATYPE_TITLE);
166 }
162 } 167 }
163 return 0; 168 return 0;
164} 169}
@@ -177,25 +182,34 @@ libextractor_nsfe_auth_extract (const char *data, size_t size,
177 if (left < 1) 182 if (left < 1)
178 return 0; 183 return 0;
179 album = nsfestring (&data[size - left], left); 184 album = nsfestring (&data[size - left], left);
180 left -= (strlen (album) + 1); 185 if (album != NULL)
181 ADDF (album, EXTRACTOR_METATYPE_ALBUM); 186 {
182 if (left < 1) 187 left -= (strlen (album) + 1);
183 return 0; 188 ADDF (album, EXTRACTOR_METATYPE_ALBUM);
189 if (left < 1)
190 return 0;
191 }
184 192
185 artist = nsfestring (&data[size - left], left); 193 artist = nsfestring (&data[size - left], left);
186 left -= (strlen (artist) + 1); 194 if (artist != NULL)
187 ADDF (artist, EXTRACTOR_METATYPE_ARTIST); 195 {
188 if (left < 1) 196 left -= (strlen (artist) + 1);
189 return 0; 197 ADDF (artist, EXTRACTOR_METATYPE_ARTIST);
198 if (left < 1)
199 return 0;
200 }
190 201
191 copyright = nsfestring (&data[size - left], left); 202 copyright = nsfestring (&data[size - left], left);
192 left -= (strlen (copyright) + 1); 203 if (copyright != NULL)
193 ADDF (copyright, EXTRACTOR_METATYPE_COPYRIGHT); 204 {
194 if (left < 1) 205 left -= (strlen (copyright) + 1);
195 return 0; 206 ADDF (copyright, EXTRACTOR_METATYPE_COPYRIGHT);
196 207 if (left < 1)
208 return 0;
209 }
197 ripper = nsfestring (&data[size - left], left); 210 ripper = nsfestring (&data[size - left], left);
198 ADDF (ripper, EXTRACTOR_METATYPE_RIPPER); 211 if (ripper != NULL)
212 ADDF (ripper, EXTRACTOR_METATYPE_RIPPER);
199 return 0; 213 return 0;
200} 214}
201 215
diff --git a/src/plugins/tiff_extractor.c b/src/plugins/tiff_extractor.c
index b58e732..d944be1 100644
--- a/src/plugins/tiff_extractor.c
+++ b/src/plugins/tiff_extractor.c
@@ -30,6 +30,8 @@ addKeyword (EXTRACTOR_MetaDataProcessor proc,
30 const char *keyword, 30 const char *keyword,
31 enum EXTRACTOR_MetaType type) 31 enum EXTRACTOR_MetaType type)
32{ 32{
33 if (keyword == NULL)
34 return 0;
33 return proc (proc_cls, 35 return proc (proc_cls,
34 "tiff", 36 "tiff",
35 type, 37 type,
@@ -188,7 +190,10 @@ EXTRACTOR_tiff_extract (const char *data,
188 snprintf (tmp, 190 snprintf (tmp,
189 sizeof(tmp), "%ux%u", 191 sizeof(tmp), "%ux%u",
190 width, length); 192 width, length);
191 addKeyword (proc, proc_cls, strdup (tmp), EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); 193 addKeyword (proc,
194 proc_cls,
195 tmp,
196 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS);
192 } 197 }
193 break; 198 break;
194 case TAG_WIDTH: 199 case TAG_WIDTH:
@@ -203,7 +208,9 @@ EXTRACTOR_tiff_extract (const char *data,
203 sizeof(tmp), 208 sizeof(tmp),
204 "%ux%u", 209 "%ux%u",
205 width, length); 210 width, length);
206 addKeyword (proc, proc_cls, strdup (tmp), EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); 211 addKeyword (proc, proc_cls,
212 tmp,
213 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS);
207 } 214 }
208 break; 215 break;
209 case TAG_SOFTWARE: 216 case TAG_SOFTWARE: