Changeset 2561

Show
Ignore:
Timestamp:
07/11/07 16:34:00 (1 year ago)
Author:
dhozac
Message:

Add some sanity checking.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/h2ext.c

    r2558 r2561  
    4646#define MAX_PEEK_SIZE 4096 
    4747#define MIN(a,b)  (((a) > (b)) ? (b) : (a)) 
     48#define STRINGIFY_(x)   #x 
     49#define STRINGIFY(x)    STRINGIFY_(x) 
    4850 
    4951struct file_format { 
     
    274276    i->next = NULL; 
    275277 
    276 #define get_field()  for (ptr++; *ptr == '\t' && *ptr != '\0'; ptr++); \ 
    277       for (field = ptr; *ptr != '\t' && *ptr != '\0'; ptr++); \ 
    278       *ptr = '\0'; 
     278#define get_field()     if (*(ptr+1) == '\0') goto new_line_and_free; \ 
     279                        for (ptr++; *ptr == '\t' && *ptr != '\0'; ptr++); \ 
     280                        for (field = ptr; *ptr != '\t' && *ptr != '\0'; ptr++); \ 
     281                        *ptr = '\0'; 
    279282    field = ptr = buf; 
    280283    while (*ptr != '\t' && *ptr != '\0') 
     
    362365    i->peek_inside = (int)strtol(field, NULL, 0); 
    363366 
     367    /* sanity check the entry */ 
     368    if (i->offset < 0) { 
     369      WRITE_MSG(2, ENSC_WRAPPERS_PREFIX); 
     370      WRITE_STR(2, file); 
     371      WRITE_MSG(2, ":"); 
     372      WRITE_INT(2, line_no); 
     373      WRITE_MSG(2, " has an invalid offset: "); 
     374      WRITE_INT(2, i->offset); 
     375      WRITE_MSG(2, "\n"); 
     376      goto new_line_and_free; 
     377    } 
     378    else if ((i->offset + i->len) > MAX_PEEK_SIZE) { 
     379      WRITE_MSG(2, ENSC_WRAPPERS_PREFIX); 
     380      WRITE_STR(2, file); 
     381      WRITE_MSG(2, ":"); 
     382      WRITE_INT(2, line_no); 
     383      WRITE_MSG(2, " exceeds maximum offset (" STRINGIFY(MAX_PEEK_SIZE) ")\n"); 
     384      goto new_line_and_free; 
     385    } 
    364386#undef get_field 
    365387    goto new_line;