libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 4542314a64d37446c444fda15f14da6b76f82343
parent a666aaa2851d695efef37bc431645522a6d8e7f9
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 15 Oct 2017 19:48:43 +0200

avoid passing of char to isspace()-family of functions, always pass unsigned chars

Diffstat:
MChangeLog | 3++-
Msrc/plugins/deb_extractor.c | 26++++++++++++++------------
Msrc/plugins/jpeg_extractor.c | 2+-
Msrc/plugins/pdf_extractor.c | 2+-
Msrc/plugins/ps_extractor.c | 16++++++++--------
5 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,6 +1,7 @@ Sun Oct 15 19:36:41 CEST 2017 Fix potential file descriptor leak (on error handling path). - Fix potential assign-after-free (on IPC error handling path). -CG + Fix potential assign-after-free (on IPC error handling path). + Make sure to only pass "unsigned char" to functions like isspace(). -CG Fri Oct 13 12:30:37 CEST 2017 Properly check read error in NSF plugin (from signedness confusion) found by Leon Zhao. -CG diff --git a/src/plugins/deb_extractor.c b/src/plugins/deb_extractor.c @@ -19,7 +19,7 @@ */ /** * @file plugins/deb_extractor.c - * @brief plugin to support Debian archives + * @brief plugin to support Debian archives * @author Christian Grothoff * * The .deb is an ar-chive file. It contains a tar.gz file @@ -86,7 +86,7 @@ struct Matches /** * Map from deb-control entries to LE types. * - * see also: "man 5 deb-control" + * see also: "man 5 deb-control" */ static struct Matches tmap[] = { {"Package: ", EXTRACTOR_METATYPE_PACKAGE_NAME}, @@ -131,7 +131,7 @@ processControl (const char *data, size_t colon; size_t eol; unsigned int i; - + pos = 0; while (pos < size) { @@ -159,7 +159,7 @@ processControl (const char *data, free (key); return 0; } - if (0 != proc (proc_cls, + if (0 != proc (proc_cls, "deb", tmap[i].type, EXTRACTOR_METAFORMAT_UTF8, @@ -190,7 +190,7 @@ struct TarHeader * Filename. */ char name[100]; - + /** * File access modes. */ @@ -210,7 +210,7 @@ struct TarHeader * Size of the file, in octal. */ char filesize[12]; - + /** * Last modification time. */ @@ -363,6 +363,8 @@ processControlTGZ (struct EXTRACTOR_ExtractContext *ec, if (size > MAX_CONTROL_SIZE) return 0; + if (0 == size) + return 0; if (NULL == (cdata = malloc (size))) return 0; off = 0; @@ -392,12 +394,12 @@ processControlTGZ (struct EXTRACTOR_ExtractContext *ec, strm.next_in = (Bytef *) data; strm.avail_in = size; if (Z_OK == inflateInit2 (&strm, 15 + 32)) - { + { strm.next_out = (Bytef *) buf; strm.avail_out = bufSize; inflate (&strm, Z_FINISH); if (strm.total_out > 0) - ret = processControlTar (buf, strm.total_out, + ret = processControlTar (buf, strm.total_out, ec->proc, ec->cls); inflateEnd (&strm); } @@ -450,11 +452,11 @@ struct ObjectHeader /** - * Main entry method for the DEB extraction plugin. + * Main entry method for the DEB extraction plugin. * * @param ec extraction context provided to the plugin */ -void +void EXTRACTOR_deb_extract_method (struct EXTRACTOR_ExtractContext *ec) { uint64_t pos; @@ -493,7 +495,7 @@ EXTRACTOR_deb_extract_method (struct EXTRACTOR_ExtractContext *ec) if ((pos + csize > fsize) || (csize > fsize) || (pos + csize < pos)) return; if (0 == strncmp (&hdr->name[0], - "control.tar.gz", + "control.tar.gz", strlen ("control.tar.gz"))) { if (0 != processControlTGZ (ec, @@ -504,7 +506,7 @@ EXTRACTOR_deb_extract_method (struct EXTRACTOR_ExtractContext *ec) if (0 == strncmp (&hdr->name[0], "debian-binary", strlen ("debian-binary"))) { - if (0 != ec->proc (ec->cls, + if (0 != ec->proc (ec->cls, "deb", EXTRACTOR_METATYPE_MIMETYPE, EXTRACTOR_METAFORMAT_UTF8, diff --git a/src/plugins/jpeg_extractor.c b/src/plugins/jpeg_extractor.c @@ -162,7 +162,7 @@ EXTRACTOR_jpeg_extract_method (struct EXTRACTOR_ExtractContext *ec) continue; off = 0; while ( (off < mptr->data_length) && - (isspace ((int) ((const char *)mptr->data)[mptr->data_length - 1 - off])) ) + (isspace (((const unsigned char *)mptr->data)[mptr->data_length - 1 - off])) ) off++; if (0 != ec->proc (ec->cls, diff --git a/src/plugins/pdf_extractor.c b/src/plugins/pdf_extractor.c @@ -100,7 +100,7 @@ process_stdout (FILE *fout, if (NULL == colon) break; psuffix = colon + 1; - while (isblank ((int) psuffix[0])) + while (isblank ((unsigned char) psuffix[0])) psuffix++; if (0 == strlen (psuffix)) continue; diff --git a/src/plugins/ps_extractor.c b/src/plugins/ps_extractor.c @@ -49,7 +49,7 @@ struct Matches * PS header prefix. */ const char *prefix; - + /** * Corresponding LE type. */ @@ -106,7 +106,7 @@ readline (struct EXTRACTOR_ExtractContext *ec) pos = ec->seek (ec->cls, 0, SEEK_CUR); if (0 >= (ret = ec->read (ec->cls, &data, MAX_LINE))) - return NULL; + return NULL; cdata = data; if (NULL == (eol = memchr (cdata, '\n', ret))) return NULL; /* no end-of-line found */ @@ -120,7 +120,7 @@ readline (struct EXTRACTOR_ExtractContext *ec) /** - * Main entry method for the 'application/postscript' extraction plugin. + * Main entry method for the 'application/postscript' extraction plugin. * * @param ec extraction context provided to the plugin */ @@ -152,7 +152,7 @@ EXTRACTOR_ps_extract_method (struct EXTRACTOR_ExtractContext *ec) "application/postscript", strlen ("application/postscript") + 1)) return; - + line = NULL; next = readline (ec); while ( (NULL != next) && @@ -170,8 +170,8 @@ EXTRACTOR_ps_extract_method (struct EXTRACTOR_ExtractContext *ec) while ( (NULL != next) && (0 == strncmp (next, "%%+", strlen ("%%+"))) ) { - if (NULL == (acc = malloc (strlen (line) + strlen (next) - 1))) - break; + if (NULL == (acc = malloc (strlen (line) + strlen (next) - 1))) + break; strcpy (acc, line); strcat (acc, " "); strcat (acc, next + 3); @@ -180,7 +180,7 @@ EXTRACTOR_ps_extract_method (struct EXTRACTOR_ExtractContext *ec) free (next); next = readline (ec); } - if ( (line[strlen (line) - 1] == ')') && + if ( (line[strlen (line) - 1] == ')') && (line[strlen (match)] == '(') ) { acc = &line[strlen (match) + 1]; @@ -190,7 +190,7 @@ EXTRACTOR_ps_extract_method (struct EXTRACTOR_ExtractContext *ec) { acc = &line[strlen (match)]; } - while (isspace ((unsigned int) acc[0])) + while (isspace ((unsigned char) acc[0])) acc++; if ( (strlen (acc) > 0) && (0 != ec->proc (ec->cls,