[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11695 - in Extractor: . src/common src/main src/plugins
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11695 - in Extractor: . src/common src/main src/plugins |
Date: |
Sat, 12 Jun 2010 22:33:10 +0200 |
Author: grothoff
Date: 2010-06-12 22:33:10 +0200 (Sat, 12 Jun 2010)
New Revision: 11695
Modified:
Extractor/ChangeLog
Extractor/src/common/convert.c
Extractor/src/main/extract.c
Extractor/src/main/extractor.c
Extractor/src/main/extractor_print.c
Extractor/src/main/iconv.c
Extractor/src/plugins/gif_extractor.c
Extractor/src/plugins/html_extractor.c
Extractor/src/plugins/id3v23_extractor.c
Extractor/src/plugins/id3v24_extractor.c
Extractor/src/plugins/id3v2_extractor.c
Extractor/src/plugins/ole2_extractor.c
Extractor/src/plugins/pdf_extractor.cc
Extractor/src/plugins/ps_extractor.c
Extractor/src/plugins/zip_extractor.c
Log:
bugfixes
Modified: Extractor/ChangeLog
===================================================================
--- Extractor/ChangeLog 2010-06-12 19:33:42 UTC (rev 11694)
+++ Extractor/ChangeLog 2010-06-12 20:33:10 UTC (rev 11695)
@@ -1,3 +1,7 @@
+Sat Jun 12 22:32:32 CEST 2010
+ Fixing various bugs, including some that can cause crashes given
+ malformed inputs. -CG
+
Sat Jun 12 16:23:14 CEST 2010
Only pass 'unsigned char's to 'isspace' and similar functions. -CG
Modified: Extractor/src/common/convert.c
===================================================================
--- Extractor/src/common/convert.c 2010-06-12 19:33:42 UTC (rev 11694)
+++ Extractor/src/common/convert.c 2010-06-12 20:33:10 UTC (rev 11695)
@@ -47,6 +47,8 @@
return strdup (i);
tmpSize = 3 * len + 4;
tmp = malloc (tmpSize);
+ if (tmp == NULL)
+ return NULL;
itmp = tmp;
finSize = tmpSize;
if (iconv (cd, (char **) &input, &len, &itmp, &finSize) == (size_t) - 1)
@@ -56,6 +58,11 @@
return strdup (i);
}
ret = malloc (tmpSize - finSize + 1);
+ if (ret == NULL)
+ {
+ free (tmp);
+ return NULL;
+ }
memcpy (ret, tmp, tmpSize - finSize);
ret[tmpSize - finSize] = '\0';
free (tmp);
Modified: Extractor/src/main/extract.c
===================================================================
--- Extractor/src/main/extract.c 2010-06-12 19:33:42 UTC (rev 11694)
+++ Extractor/src/main/extract.c 2010-06-12 20:33:10 UTC (rev 11695)
@@ -253,11 +253,14 @@
data);
else
keyword = strdup(data);
- fprintf (stdout,
- "%s - %s\n",
- stype,
- keyword);
- free(keyword);
+ if (keyword != NULL)
+ {
+ fprintf (stdout,
+ "%s - %s\n",
+ stype,
+ keyword);
+ free(keyword);
+ }
if (cd != (iconv_t) -1)
iconv_close(cd);
break;
@@ -327,10 +330,13 @@
data);
else
keyword = strdup(data);
- fprintf (stdout,
- "'%s' ",
- keyword);
- free(keyword);
+ if (keyword != NULL)
+ {
+ fprintf (stdout,
+ "'%s' ",
+ keyword);
+ free(keyword);
+ }
if (cd != (iconv_t) -1)
iconv_close(cd);
break;
Modified: Extractor/src/main/extractor.c
===================================================================
--- Extractor/src/main/extractor.c 2010-06-12 19:33:42 UTC (rev 11694)
+++ Extractor/src/main/extractor.c 2010-06-12 20:33:10 UTC (rev 11695)
@@ -175,6 +175,7 @@
char line[1024];
char dir[1024];
char * lnk;
+ char * ret;
char * lestr;
size_t size;
FILE * f;
@@ -222,11 +223,14 @@
}
lnk[size] = '\0';
lnk = cut_bin(lnk);
- lnk = realloc(lnk, strlen(lnk) + 5);
- if (lnk == NULL)
- return NULL;
- strcat(lnk, "lib/"); /* guess "lib/" as the library dir */
- return lnk;
+ ret = realloc(lnk, strlen(lnk) + 5);
+ if (ret == NULL)
+ {
+ free (lnk);
+ return NULL;
+ }
+ strcat(ret, "lib/"); /* guess "lib/" as the library dir */
+ return ret;
}
#endif
@@ -234,11 +238,15 @@
/**
* Try to determine path with win32-specific function
*/
-static char * get_path_from_module_filename() {
+static char *
+get_path_from_module_filename() {
char * path;
+ char * ret;
char * idx;
path = malloc(4103); /* 4096+nil+6 for "/lib/" catenation */
+ if (path == NULL)
+ return NULL;
GetModuleFileName(NULL, path, 4096);
idx = path + strlen(path);
while ( (idx > path) &&
@@ -247,9 +255,14 @@
idx--;
*idx = '\0';
path = cut_bin(path);
- path = realloc(path, strlen(path) + 6);
- strcat(path, "/lib/"); /* guess "lib/" as the library dir */
- return path;
+ ret = realloc(path, strlen(path) + 6);
+ if (ret == NULL)
+ {
+ free (path);
+ return NULL;
+ }
+ strcat(ret, "/lib/"); /* guess "lib/" as the library dir */
+ return ret;
}
#endif
@@ -293,6 +306,7 @@
char * pos;
char * end;
char * buf;
+ char * ret;
const char * p;
size_t size;
@@ -321,11 +335,14 @@
if (pos == NULL)
return NULL;
pos = cut_bin(pos);
- pos = realloc(pos, strlen(pos) + 5);
- if (pos == NULL)
- return NULL;
- strcat(pos, "lib/");
- return pos;
+ ret = realloc(pos, strlen(pos) + 5);
+ if (ret == NULL)
+ {
+ free (pos);
+ return NULL;
+ }
+ strcat(ret, "lib/");
+ return ret;
}
pos = end + 1;
}
@@ -337,11 +354,14 @@
if (pos == NULL)
return NULL;
pos = cut_bin(pos);
- pos = realloc(pos, strlen(pos) + 5);
- if (pos == NULL)
- return NULL;
- strcat(pos, "lib/");
- return pos;
+ ret = realloc(pos, strlen(pos) + 5);
+ if (ret == NULL)
+ {
+ free (pos);
+ return NULL;
+ }
+ strcat(ret, "lib/");
+ return ret;
}
free(buf);
free(path);
@@ -1157,6 +1177,12 @@
HANDLE map;
#endif
+ if (plugin == NULL)
+ {
+ close (in);
+ close (out);
+ return;
+ }
if (0 != plugin_load (plugin))
{
close (in);
@@ -1269,11 +1295,9 @@
i = strlen (plugin->libname) + 1;
write (fd, &i, sizeof (size_t));
write (fd, plugin->libname, i);
-
i = strlen (plugin->short_libname) + 1;
write (fd, &i, sizeof (size_t));
write (fd, plugin->short_libname, i);
-
if (plugin->plugin_options != NULL)
{
i = strlen (plugin->plugin_options) + 1;
@@ -1281,11 +1305,11 @@
}
else
{
- i = 1;
- str = "";
+ i = 0;
}
write (fd, &i, sizeof (size_t));
- write (fd, str, i);
+ if (i > 0)
+ write (fd, str, i);
}
static struct EXTRACTOR_PluginList *
@@ -1295,34 +1319,62 @@
size_t i;
ret = malloc (sizeof (struct EXTRACTOR_PluginList));
-
+ if (ret == NULL)
+ return NULL;
read (fd, &i, sizeof (size_t));
ret->libname = malloc (i);
+ if (ret->libname == NULL)
+ {
+ free (ret);
+ return NULL;
+ }
read (fd, ret->libname, i);
read (fd, &i, sizeof (size_t));
ret->short_libname = malloc (i);
+ if (ret->short_libname == NULL)
+ {
+ free (ret->libname);
+ free (ret);
+ return NULL;
+ }
read (fd, ret->short_libname, i);
read (fd, &i, sizeof (size_t));
- ret->plugin_options = malloc (i);
- read (fd, ret->plugin_options, i);
-
+ if (i == 0)
+ {
+ ret->plugin_options = NULL;
+ }
+ else
+ {
+ ret->plugin_options = malloc (i);
+ if (ret->plugin_options == NULL)
+ {
+ free (ret->short_libname);
+ free (ret->libname);
+ free (ret);
+ return NULL;
+ }
+ read (fd, ret->plugin_options, i);
+ }
return ret;
}
void CALLBACK
-RundllEntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
+RundllEntryPoint(HWND hwnd,
+ HINSTANCE hinst,
+ LPSTR lpszCmdLine,
+ int nCmdShow)
{
- int in, out;
+ int in;
+ int out;
sscanf(lpszCmdLine, "%u %u", &in, &out);
-
setmode (in, _O_BINARY);
setmode (out, _O_BINARY);
-
- process_requests (read_plugin_data (in), in, out);
+ process_requests (read_plugin_data (in),
+ in, out);
}
#endif
@@ -1805,6 +1857,7 @@
EXTRACTOR_MetaDataProcessor proc,
void *proc_cls) {
unsigned char * buf;
+ unsigned char * rbuf;
size_t dsize;
#if HAVE_ZLIB
z_stream strm;
@@ -1936,7 +1989,14 @@
dsize *= 2;
if (dsize > MAX_DECOMPRESS)
dsize = MAX_DECOMPRESS;
- buf = realloc(buf, dsize);
+ rbuf = realloc(buf, dsize);
+ if (rbuf == NULL)
+ {
+ free (buf);
+ buf = NULL;
+ break;
+ }
+ buf = rbuf;
strm.next_out = (Bytef*) &buf[pos];
strm.avail_out = dsize - pos;
}
@@ -1950,10 +2010,12 @@
(ret != Z_STREAM_END) );
dsize = pos + strm.total_out;
inflateEnd(&strm);
- if (dsize == 0) {
- free(buf);
- buf = NULL;
- }
+ if ( (dsize == 0) &&
+ (buf != NULL) )
+ {
+ free(buf);
+ buf = NULL;
+ }
}
}
}
@@ -2005,7 +2067,14 @@
dsize *= 2;
if (dsize > MAX_DECOMPRESS)
dsize = MAX_DECOMPRESS;
- buf = realloc(buf, dsize);
+ rbuf = realloc(buf, dsize);
+ if (rbuf == NULL)
+ {
+ free (buf);
+ buf = NULL;
+ break;
+ }
+ buf = rbuf;
bstrm.next_out = (char*) &buf[bpos];
bstrm.avail_out = dsize - bpos;
}
@@ -2019,7 +2088,8 @@
(bret != BZ_STREAM_END) );
dsize = bpos + bstrm.total_out_lo32;
BZ2_bzDecompressEnd(&bstrm);
- if (dsize == 0)
+ if ( (dsize == 0) &&
+ (buf != NULL) )
{
free(buf);
buf = NULL;
Modified: Extractor/src/main/extractor_print.c
===================================================================
--- Extractor/src/main/extractor_print.c 2010-06-12 19:33:42 UTC (rev
11694)
+++ Extractor/src/main/extractor_print.c 2010-06-12 20:33:10 UTC (rev
11695)
@@ -59,12 +59,19 @@
if (cd == (iconv_t) -1)
return 1;
buf = iconv_helper(cd, data);
- ret = fprintf(handle,
- "%s - %s\n",
- dgettext ("libextractor",
- EXTRACTOR_metatype_to_string (type)),
- buf);
- free(buf);
+ if (buf != NULL)
+ {
+ ret = fprintf(handle,
+ "%s - %s\n",
+ dgettext ("libextractor",
+ EXTRACTOR_metatype_to_string (type)),
+ buf);
+ free(buf);
+ }
+ else
+ {
+ ret = -1;
+ }
iconv_close(cd);
if (ret < 0)
return 1;
Modified: Extractor/src/main/iconv.c
===================================================================
--- Extractor/src/main/iconv.c 2010-06-12 19:33:42 UTC (rev 11694)
+++ Extractor/src/main/iconv.c 2010-06-12 20:33:10 UTC (rev 11695)
@@ -40,6 +40,8 @@
outSize = 4 * strlen(in) + 2;
outLeft = outSize - 2; /* make sure we have 2 0-terminations! */
buf = malloc(outSize);
+ if (buf == NULL)
+ return NULL;
ibuf = buf;
memset(buf, 0, outSize);
if (iconv(cd,
Modified: Extractor/src/plugins/gif_extractor.c
===================================================================
--- Extractor/src/plugins/gif_extractor.c 2010-06-12 19:33:42 UTC (rev
11694)
+++ Extractor/src/plugins/gif_extractor.c 2010-06-12 20:33:10 UTC (rev
11695)
@@ -153,7 +153,6 @@
{
size_t length = 0;
size_t curr = pos;
- char *comment;
int ret;
while ((data[curr] != 0) && (curr < size))
@@ -161,26 +160,32 @@
length += data[curr];
curr += data[curr] + 1;
}
- comment = malloc (length + 1);
- curr = pos;
- length = 0;
- while ((data[curr] != 0) && (curr < size))
+ if (length < 65536)
{
- length += data[curr];
- if (length >= size)
- break;
- memcpy (&comment[length - data[curr]], &data[curr] + 1, data[curr]);
- comment[length] = '\0';
- curr += data[curr] + 1;
+ char comment[length+1];
+ curr = pos;
+ length = 0;
+ while ((data[curr] != 0) && (curr < size))
+ {
+ length += data[curr];
+ if (length >= size)
+ break;
+ memcpy (&comment[length - data[curr]], &data[curr] + 1, data[curr]);
+ comment[length] = '\0';
+ curr += data[curr] + 1;
+ }
+ ret = proc (proc_cls,
+ "gif",
+ EXTRACTOR_METATYPE_COMMENT,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ comment,
+ length+1);
}
- ret = proc (proc_cls,
- "gif",
- EXTRACTOR_METATYPE_COMMENT,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- comment,
- length+1);
- free (comment);
+ else
+ {
+ ret = 0;
+ }
return ret;
}
Modified: Extractor/src/plugins/html_extractor.c
===================================================================
--- Extractor/src/plugins/html_extractor.c 2010-06-12 19:33:42 UTC (rev
11694)
+++ Extractor/src/plugins/html_extractor.c 2010-06-12 20:33:10 UTC (rev
11695)
@@ -205,6 +205,8 @@
if (pstart != NULL)
{
char *ret = malloc (pend - pstart + 1);
+ if (ret == NULL)
+ return NULL;
memcpy (ret, pstart, pend - pstart);
ret[pend - pstart] = '\0';
return ret;
@@ -290,6 +292,8 @@
tag.tagStart, tag.tagEnd - tag.tagStart)))
{
t = malloc (sizeof (TagInfo));
+ if (t == NULL)
+ return 0;
*t = tag;
t->next = tags;
tags = t;
@@ -357,7 +361,8 @@
free (xtmp);
}
}
- free (tmp);
+ if (tmp != NULL)
+ free (tmp);
i++;
}
while (tags != NULL)
@@ -369,16 +374,19 @@
if (charset == NULL)
{
xtmp = malloc (t->dataEnd - t->dataStart + 1);
- memcpy (xtmp, t->dataStart, t->dataEnd - t->dataStart);
- xtmp[t->dataEnd - t->dataStart] = '\0';
- ret = proc (proc_cls,
- "html",
- EXTRACTOR_METATYPE_TITLE,
- EXTRACTOR_METAFORMAT_C_STRING,
- "text/plain",
- xtmp,
- strlen (xtmp) + 1);
- free (xtmp);
+ if (xtmp != NULL)
+ {
+ memcpy (xtmp, t->dataStart, t->dataEnd - t->dataStart);
+ xtmp[t->dataEnd - t->dataStart] = '\0';
+ ret = proc (proc_cls,
+ "html",
+ EXTRACTOR_METATYPE_TITLE,
+ EXTRACTOR_METAFORMAT_C_STRING,
+ "text/plain",
+ xtmp,
+ strlen (xtmp) + 1);
+ free (xtmp);
+ }
}
else
{
Modified: Extractor/src/plugins/id3v23_extractor.c
===================================================================
--- Extractor/src/plugins/id3v23_extractor.c 2010-06-12 19:33:42 UTC (rev
11694)
+++ Extractor/src/plugins/id3v23_extractor.c 2010-06-12 20:33:10 UTC (rev
11695)
@@ -356,8 +356,9 @@
(data[pos+off] != '\0') )
return 0; /* malformed */
off++;
- if (0 == strcasecmp ("-->",
- mime))
+ if ( (mime != NULL) &&
+ (0 == strcasecmp ("-->",
+ mime)) )
{
/* not supported */
}
@@ -371,11 +372,13 @@
(const char*) &data[pos + off],
csize + 6 - off))
{
- free (mime);
+ if (mime != NULL)
+ free (mime);
return 1;
}
}
- free (mime);
+ if (mime != NULL)
+ free (mime);
word = NULL;
break;
default:
@@ -395,7 +398,8 @@
return 1;
}
}
- free (word);
+ if (word != NULL)
+ free (word);
break;
}
i++;
Modified: Extractor/src/plugins/id3v24_extractor.c
===================================================================
--- Extractor/src/plugins/id3v24_extractor.c 2010-06-12 19:33:42 UTC (rev
11694)
+++ Extractor/src/plugins/id3v24_extractor.c 2010-06-12 20:33:10 UTC (rev
11695)
@@ -366,8 +366,9 @@
(data[pos+off] != '\0') )
return 0; /* malformed */
off++;
- if (0 == strcasecmp ("-->",
- mime))
+ if ( (mime != NULL) &&
+ (0 == strcasecmp ("-->",
+ mime)) )
{
/* not supported */
}
@@ -381,11 +382,13 @@
(const char*) &data[pos + off],
csize + 6 - off))
{
- free (mime);
+ if (mime != NULL)
+ free (mime);
return 1;
}
}
- free (mime);
+ if (mime != NULL)
+ free (mime);
word = NULL;
break;
default:
@@ -405,7 +408,8 @@
return 1;
}
}
- free (word);
+ if (word != NULL)
+ free (word);
break;
}
i++;
Modified: Extractor/src/plugins/id3v2_extractor.c
===================================================================
--- Extractor/src/plugins/id3v2_extractor.c 2010-06-12 19:33:42 UTC (rev
11694)
+++ Extractor/src/plugins/id3v2_extractor.c 2010-06-12 20:33:10 UTC (rev
11695)
@@ -347,7 +347,8 @@
return 1;
}
}
- free (word);
+ if (word != NULL)
+ free (word);
break;
}
i++;
Modified: Extractor/src/plugins/ole2_extractor.c
===================================================================
--- Extractor/src/plugins/ole2_extractor.c 2010-06-12 19:33:42 UTC (rev
11694)
+++ Extractor/src/plugins/ole2_extractor.c 2010-06-12 20:33:10 UTC (rev
11695)
@@ -430,6 +430,8 @@
if (gsf_input_remaining(stream) < lcbSttbSavedBy)
return 0;
lbuffer = malloc(lcbSttbSavedBy);
+ if (lbuffer == NULL)
+ return 0;
// read all the revision history
gsf_input_read(stream, lcbSttbSavedBy, lbuffer);
// there are n strings, so n/2 revisions (author & file)
@@ -444,29 +446,41 @@
(where + 2 * length + 2 <= where) )
break;
author = EXTRACTOR_common_convert_to_utf8((const char*) &lbuffer[where],
- length * 2,
- "UTF-16BE");
+ length * 2,
+ "UTF-16BE");
where += length * 2 + 1;
length = lbuffer[where++];
if ( (where + 2 * length >= lcbSttbSavedBy) ||
(where + 2 * length + 1 <= where) ) {
- free(author);
+ if (author != NULL)
+ free(author);
break;
}
filename = EXTRACTOR_common_convert_to_utf8((const char*) &lbuffer[where],
- length * 2,
- "UTF-16BE");
+ length * 2,
+ "UTF-16BE");
where += length * 2 + 1;
- rbuf = malloc(strlen(author) + strlen(filename) + 512);
- snprintf(rbuf, 512 + strlen(author) + strlen(filename),
- _("Revision #%u: Author '%s' worked on '%s'"),
- i, author, filename);
- free(author);
- free(filename);
- ret = addKeyword(proc, proc_cls,
- rbuf,
- EXTRACTOR_METATYPE_REVISION_HISTORY);
- free(rbuf);
+ if ( (author != NULL) &&
+ (filename != NULL) )
+ {
+ rbuf = malloc(strlen(author) + strlen(filename) + 512);
+ if (rbuf != NULL)
+ {
+ snprintf(rbuf,
+ 512 + strlen(author) + strlen(filename),
+ _("Revision #%u: Author '%s' worked on '%s'"),
+ i, author, filename);
+ ret = addKeyword(proc, proc_cls,
+ rbuf,
+ EXTRACTOR_METATYPE_REVISION_HISTORY);
+ if (rbuf != NULL)
+ free(rbuf);
+ }
+ }
+ if (author != NULL)
+ free(author);
+ if (filename != NULL)
+ free(filename);
if (0 != ret)
break;
}
Modified: Extractor/src/plugins/pdf_extractor.cc
===================================================================
--- Extractor/src/plugins/pdf_extractor.cc 2010-06-12 19:33:42 UTC (rev
11694)
+++ Extractor/src/plugins/pdf_extractor.cc 2010-06-12 20:33:10 UTC (rev
11695)
@@ -56,6 +56,8 @@
int err = 0;
char * result;
+ if (ckey == NULL)
+ return 0;
result = NULL;
if (infoDict->lookup(ckey, &obj)->isString()) {
s1 = obj.getString();
@@ -63,7 +65,8 @@
if ((((unsigned char)s[0]) & 0xff) == 0xfe &&
(((unsigned char)s[1]) & 0xff) == 0xff) {
result = EXTRACTOR_common_convert_to_utf8(&s[2], s1->getLength() - 2,
"UTF-16BE");
- ADD (result, type);
+ if (result != NULL)
+ ADD (result, type);
} else {
size_t len = strlen(s);
@@ -95,13 +98,15 @@
if (0 < len) {
result = EXTRACTOR_common_convert_to_utf8(s, len,
"ISO-8859-1");
- ADD (result, type);
+ if (result != NULL)
+ ADD (result, type);
}
}
}
EXIT:
obj.free();
- free (result);
+ if (result != NULL)
+ free (result);
free (ckey);
return err;
}
@@ -123,6 +128,8 @@
err = 0;
result = NULL;
gkey = strdup (key);
+ if (gkey == NULL)
+ return 0;
if (infoDict->lookup(gkey, &obj)->isString()) {
s1 = obj.getString();
s = s1->getCString();
@@ -132,7 +139,8 @@
/* isUnicode */
result = EXTRACTOR_common_convert_to_utf8((const char*)&s[2],
s1->getLength() - 2, "UTF-16BE");
- ADD (result, type);
+ if (result != NULL)
+ ADD (result, type);
} else {
if (s[0] == 'D' && s[1] == ':')
s += 2;
@@ -143,7 +151,8 @@
}
EXIT:
obj.free();
- free (result);
+ if (result != NULL)
+ free (result);
free (gkey);
return err;
}
Modified: Extractor/src/plugins/ps_extractor.c
===================================================================
--- Extractor/src/plugins/ps_extractor.c 2010-06-12 19:33:42 UTC (rev
11694)
+++ Extractor/src/plugins/ps_extractor.c 2010-06-12 20:33:10 UTC (rev
11695)
@@ -154,7 +154,8 @@
while ( (line == NULL) ||
(0 != strncmp ("%%EndComments", line, strlen ("%%EndComments"))) )
{
- free (line);
+ if (line != NULL)
+ free (line);
line = readline (data, size, pos);
if (line == NULL)
break;
@@ -186,7 +187,8 @@
break; /* overflow */
pos += strlen (line) + 1; /* skip newline, too; guarantee progress! */
}
- free (line);
+ if (line != NULL)
+ free (line);
return ret;
}
Modified: Extractor/src/plugins/zip_extractor.c
===================================================================
--- Extractor/src/plugins/zip_extractor.c 2010-06-12 19:33:42 UTC (rev
11694)
+++ Extractor/src/plugins/zip_extractor.c 2010-06-12 20:33:10 UTC (rev
11695)
@@ -88,7 +88,7 @@
void *tmp;
zip_entry * info;
zip_entry * start;
- char *filecomment = NULL;
+ char *filecomment;
const unsigned char *pos;
unsigned int offset, stop;
unsigned int name_length, extra_length, comment_length;
@@ -174,8 +174,11 @@
if (filecomment_length > 0)
{
filecomment = malloc (filecomment_length + 1);
- memcpy (filecomment, &pos[22], filecomment_length);
- filecomment[filecomment_length] = '\0';
+ if (filecomment != NULL)
+ {
+ memcpy (filecomment, &pos[22], filecomment_length);
+ filecomment[filecomment_length] = '\0';
+ }
}
if ((0 != pos[4]) && (0 != pos[5]))
{
@@ -281,12 +284,16 @@
if (start == NULL)
{
start = malloc (sizeof (zip_entry));
+ if (start == NULL)
+ break;
start->next = NULL;
info = start;
}
else
{
info->next = malloc (sizeof (zip_entry));
+ if (info->next == NULL)
+ break;
info = info->next;
info->next = NULL;
}
@@ -294,35 +301,36 @@
info->comment = malloc (comment_length + 1);
/* (strings in zip files are not null terminated) */
- memcpy (info->filename, &pos[46], name_length);
- info->filename[name_length] = '\0';
- memcpy (info->comment, &pos[46 + name_length + extra_length],
- comment_length);
- info->comment[comment_length] = '\0';
-
-#if DEBUG_EXTRACT_ZIP
- fprintf (stderr, "Found file %s, Comment: %s\n", info->filename,
- info->comment);
-
-#endif
- offset += 46 + name_length + extra_length + comment_length;
- pos = &data[offset];
-
- /* check for next header entry (0x02014b50) or (0x06054b50) if at end
*/
- if (('P' != pos[0]) && ('K' != pos[1]))
+ if (info->filename != NULL)
+ {
+ memcpy (info->filename, &pos[46], name_length);
+ info->filename[name_length] = '\0';
+ }
+ if (info->comment != NULL)
+ {
+ memcpy (info->comment, &pos[46 + name_length + extra_length],
+ comment_length);
+ info->comment[comment_length] = '\0';
+ }
+ offset += 46 + name_length + extra_length + comment_length;
+ pos = &data[offset];
+ /* check for next header entry (0x02014b50) or (0x06054b50) if at end */
+ if (('P' != pos[0]) && ('K' != pos[1]))
{
-
+
#if DEBUG_EXTRACT_ZIP
- fprintf (stderr,
- "Did not find next header in central directory.\n");
+ fprintf (stderr,
+ "Did not find next header in central directory.\n");
#endif
- info = start;
+ info = start;
while (info != NULL)
{
start = info->next;
- free (info->filename);
- free (info->comment);
+ if (info->filename != NULL)
+ free (info->filename);
+ if (info->comment != NULL)
+ free (info->comment);
free (info);
info = start;
}
@@ -364,7 +372,8 @@
filecomment,
strlen (filecomment)+1);
}
- free (filecomment);
+ if (filecomment != NULL)
+ free (filecomment);
/* if we've gotten to here then there is at least one zip entry (see
get_zipinfo call above) */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11695 - in Extractor: . src/common src/main src/plugins,
gnunet <=