From: robertl Date: Wed, 29 Jul 2009 18:46:47 +0000 (+0000) Subject: Better defend TomTom module against bogus input. X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~199^2~192 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a155de9a804bda08626a206fb2891e699ab9cd7f;p=gpsbabel.git Better defend TomTom module against bogus input. --- diff --git a/tomtom.c b/tomtom.c index 33d4ac06e..ff70df155 100644 --- a/tomtom.c +++ b/tomtom.c @@ -75,7 +75,7 @@ wr_deinit(void) } #define read_long(f) gbfgetint32((f)) -#define read_char(f) (unsigned char)gbfgetc((f)) +#define read_char(f) gbfgetc((f)) /* * Decode a type 8 compressed record @@ -155,8 +155,13 @@ data_read(void) recsize = read_long( file_in ) - 5; if (global_opts.debug_level >= 5) printf("Skipping %li bytes\n", recsize ); - while (recsize-- > 0) - (void) read_char( file_in ); + while (recsize-- > 0) { + int junk; + junk = read_char( file_in ); + if (junk == EOF) { + fatal(MYNAME ":Unexpected EOF"); + } + } break; case 1: /* a block header; ignored on read */ @@ -208,8 +213,12 @@ data_read(void) if (global_opts.debug_level >= 5) warning("Unknown record type 0x%x; skipping %ld bytes.\n", rectype, recsize); - while (recsize--) - (void) read_char( file_in ); + while (recsize--) { + int junk = read_char( file_in ); + if (junk == EOF) { + fatal(MYNAME ":Unexpected EOF"); + } + } break; default: if (global_opts.debug_level >= 1) {