[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11702 - Extractor/src/plugins
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11702 - Extractor/src/plugins |
Date: |
Sun, 13 Jun 2010 01:28:36 +0200 |
Author: grothoff
Date: 2010-06-13 01:28:36 +0200 (Sun, 13 Jun 2010)
New Revision: 11702
Modified:
Extractor/src/plugins/deb_extractor.c
Extractor/src/plugins/html_extractor.c
Extractor/src/plugins/id3_extractor.c
Extractor/src/plugins/man_extractor.c
Extractor/src/plugins/nsfe_extractor.c
Extractor/src/plugins/tiff_extractor.c
Log:
null checks and a few missing frees
Modified: Extractor/src/plugins/deb_extractor.c
===================================================================
--- Extractor/src/plugins/deb_extractor.c 2010-06-12 23:18:29 UTC (rev
11701)
+++ Extractor/src/plugins/deb_extractor.c 2010-06-12 23:28:36 UTC (rev
11702)
@@ -40,6 +40,8 @@
{
char *tmp;
tmp = malloc (n + 1);
+ if (tmp == NULL)
+ return NULL;
tmp[n] = '\0';
memcpy (tmp, str, n);
return tmp;
@@ -114,12 +116,19 @@
if ((eol == colon) || (eol > size))
return 0;
key = stndup (&data[pos], colon - pos);
+ if (key == NULL)
+ return 0;
i = 0;
while (tmap[i].text != NULL)
{
if (0 == strcmp (key, tmap[i].text))
{
val = stndup (&data[colon], eol - colon);
+ if (val == NULL)
+ {
+ free (key);
+ return 0;
+ }
if (0 != proc (proc_cls,
"deb",
tmap[i].type,
Modified: Extractor/src/plugins/html_extractor.c
===================================================================
--- Extractor/src/plugins/html_extractor.c 2010-06-12 23:18:29 UTC (rev
11701)
+++ Extractor/src/plugins/html_extractor.c 2010-06-12 23:28:36 UTC (rev
11702)
@@ -339,27 +339,32 @@
(ret == 0) )
{
if (charset == NULL)
- ret = proc (proc_cls,
- "html",
- tagmap[i].type,
- EXTRACTOR_METAFORMAT_C_STRING,
- "text/plain",
- tmp,
- strlen (tmp) + 1);
- else
{
- xtmp = EXTRACTOR_common_convert_to_utf8 (tmp,
- strlen (tmp),
- charset);
ret = proc (proc_cls,
"html",
tagmap[i].type,
- EXTRACTOR_METAFORMAT_UTF8,
+ EXTRACTOR_METAFORMAT_C_STRING,
"text/plain",
- xtmp,
- strlen (xtmp) + 1);
- free (xtmp);
+ tmp,
+ strlen (tmp) + 1);
}
+ else
+ {
+ xtmp = EXTRACTOR_common_convert_to_utf8 (tmp,
+ strlen (tmp),
+ charset);
+ if (xtmp != NULL)
+ {
+ ret = proc (proc_cls,
+ "html",
+ tagmap[i].type,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ xtmp,
+ strlen (xtmp) + 1);
+ free (xtmp);
+ }
+ }
}
if (tmp != NULL)
free (tmp);
@@ -393,19 +398,23 @@
xtmp = EXTRACTOR_common_convert_to_utf8 (t->dataStart,
t->dataEnd -
t->dataStart,
charset);
- ret = proc (proc_cls,
- "html",
- EXTRACTOR_METATYPE_TITLE,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- xtmp,
- strlen (xtmp) + 1);
- free (xtmp);
+ if (xtmp != NULL)
+ {
+ ret = proc (proc_cls,
+ "html",
+ EXTRACTOR_METATYPE_TITLE,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ xtmp,
+ strlen (xtmp) + 1);
+ free (xtmp);
+ }
}
}
tags = t->next;
free (t);
}
- free (charset);
+ if (charset != NULL)
+ free (charset);
return ret;
}
Modified: Extractor/src/plugins/id3_extractor.c
===================================================================
--- Extractor/src/plugins/id3_extractor.c 2010-06-12 23:18:29 UTC (rev
11701)
+++ Extractor/src/plugins/id3_extractor.c 2010-06-12 23:28:36 UTC (rev
11702)
@@ -202,6 +202,8 @@
static void
trim (char *k)
{
+ if (k == NULL)
+ return;
while ((strlen (k) > 0) && (isspace ((unsigned char) k[strlen (k) - 1])))
k[strlen (k) - 1] = '\0';
}
@@ -251,7 +253,7 @@
}
-#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)
+#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)
const char *
@@ -275,18 +277,12 @@
ret = 0;
if (OK != get_id3 (data, size, &info))
return 0;
- if (strlen (info.title) > 0)
- ADD (info.title, EXTRACTOR_METATYPE_TITLE);
- if (strlen (info.artist) > 0)
- ADD (info.artist, EXTRACTOR_METATYPE_ARTIST);
- if (strlen (info.album) > 0)
- ADD (info.album, EXTRACTOR_METATYPE_ALBUM);
- if (strlen (info.year) > 0)
- ADD (info.year, EXTRACTOR_METATYPE_PUBLICATION_YEAR);
- if (strlen (info.genre) > 0)
- ADD (info.genre, EXTRACTOR_METATYPE_GENRE);
- if (strlen (info.comment) > 0)
- ADD (info.comment, EXTRACTOR_METATYPE_COMMENT);
+ ADD (info.title, EXTRACTOR_METATYPE_TITLE);
+ ADD (info.artist, EXTRACTOR_METATYPE_ARTIST);
+ ADD (info.album, EXTRACTOR_METATYPE_ALBUM);
+ ADD (info.year, EXTRACTOR_METATYPE_PUBLICATION_YEAR);
+ ADD (info.genre, EXTRACTOR_METATYPE_GENRE);
+ ADD (info.comment, EXTRACTOR_METATYPE_COMMENT);
if (info.track_number != 0)
{
snprintf(track,
@@ -294,11 +290,11 @@
ADD (track, EXTRACTOR_METATYPE_TRACK_NUMBER);
}
FINISH:
- free (info.title);
- free (info.year);
- free (info.album);
- free (info.artist);
- free (info.comment);
+ if (info.title != NULL) free (info.title);
+ if (info.year != NULL) free (info.year);
+ if (info.album != NULL) free (info.album);
+ if (info.artist != NULL) free (info.artist);
+ if (info.comment != NULL) free (info.comment);
return ret;
}
Modified: Extractor/src/plugins/man_extractor.c
===================================================================
--- Extractor/src/plugins/man_extractor.c 2010-06-12 23:18:29 UTC (rev
11701)
+++ Extractor/src/plugins/man_extractor.c 2010-06-12 23:28:36 UTC (rev
11702)
@@ -27,6 +27,8 @@
{
char *tmp;
tmp = malloc (n + 1);
+ if (tmp == NULL)
+ return NULL;
tmp[n] = '\0';
memcpy (tmp, str, n);
return tmp;
@@ -53,6 +55,8 @@
keyword[strlen (keyword) - 1] = '\0';
tmp = strdup (&keyword[1]);
free (keyword);
+ if (tmp == NULL)
+ return 0;
keyword = tmp;
}
if (strlen (keyword) == 0)
Modified: Extractor/src/plugins/nsfe_extractor.c
===================================================================
--- Extractor/src/plugins/nsfe_extractor.c 2010-06-12 23:18:29 UTC (rev
11701)
+++ Extractor/src/plugins/nsfe_extractor.c 2010-06-12 23:28:36 UTC (rev
11702)
@@ -84,6 +84,8 @@
(data[length] != '\0') )
length++;
s = malloc (length + 1);
+ if (s == NULL)
+ return NULL;
strncpy (s, data, length);
s[strlen (data)] = '\0';
return s;
@@ -157,8 +159,11 @@
for (left = size; left > 0; left -= length)
{
title = nsfestring (&data[size - left], left);
- length = strlen (title) + 1;
- ADDF (title, EXTRACTOR_METATYPE_TITLE);
+ if (title != NULL)
+ {
+ length = strlen (title) + 1;
+ ADDF (title, EXTRACTOR_METATYPE_TITLE);
+ }
}
return 0;
}
@@ -177,25 +182,34 @@
if (left < 1)
return 0;
album = nsfestring (&data[size - left], left);
- left -= (strlen (album) + 1);
- ADDF (album, EXTRACTOR_METATYPE_ALBUM);
- if (left < 1)
- return 0;
+ if (album != NULL)
+ {
+ left -= (strlen (album) + 1);
+ ADDF (album, EXTRACTOR_METATYPE_ALBUM);
+ if (left < 1)
+ return 0;
+ }
artist = nsfestring (&data[size - left], left);
- left -= (strlen (artist) + 1);
- ADDF (artist, EXTRACTOR_METATYPE_ARTIST);
- if (left < 1)
- return 0;
+ if (artist != NULL)
+ {
+ left -= (strlen (artist) + 1);
+ ADDF (artist, EXTRACTOR_METATYPE_ARTIST);
+ if (left < 1)
+ return 0;
+ }
copyright = nsfestring (&data[size - left], left);
- left -= (strlen (copyright) + 1);
- ADDF (copyright, EXTRACTOR_METATYPE_COPYRIGHT);
- if (left < 1)
- return 0;
-
+ if (copyright != NULL)
+ {
+ left -= (strlen (copyright) + 1);
+ ADDF (copyright, EXTRACTOR_METATYPE_COPYRIGHT);
+ if (left < 1)
+ return 0;
+ }
ripper = nsfestring (&data[size - left], left);
- ADDF (ripper, EXTRACTOR_METATYPE_RIPPER);
+ if (ripper != NULL)
+ ADDF (ripper, EXTRACTOR_METATYPE_RIPPER);
return 0;
}
Modified: Extractor/src/plugins/tiff_extractor.c
===================================================================
--- Extractor/src/plugins/tiff_extractor.c 2010-06-12 23:18:29 UTC (rev
11701)
+++ Extractor/src/plugins/tiff_extractor.c 2010-06-12 23:28:36 UTC (rev
11702)
@@ -30,6 +30,8 @@
const char *keyword,
enum EXTRACTOR_MetaType type)
{
+ if (keyword == NULL)
+ return 0;
return proc (proc_cls,
"tiff",
type,
@@ -188,7 +190,10 @@
snprintf (tmp,
sizeof(tmp), "%ux%u",
width, length);
- addKeyword (proc, proc_cls, strdup (tmp),
EXTRACTOR_METATYPE_IMAGE_DIMENSIONS);
+ addKeyword (proc,
+ proc_cls,
+ tmp,
+ EXTRACTOR_METATYPE_IMAGE_DIMENSIONS);
}
break;
case TAG_WIDTH:
@@ -203,7 +208,9 @@
sizeof(tmp),
"%ux%u",
width, length);
- addKeyword (proc, proc_cls, strdup (tmp),
EXTRACTOR_METATYPE_IMAGE_DIMENSIONS);
+ addKeyword (proc, proc_cls,
+ tmp,
+ EXTRACTOR_METATYPE_IMAGE_DIMENSIONS);
}
break;
case TAG_SOFTWARE:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11702 - Extractor/src/plugins,
gnunet <=