--- libgtop-2.14.3/sysdeps/linux/procopenfiles.c.cve-2007-0235 2005-12-12 03:09:40.000000000 -0700 +++ libgtop-2.14.3/sysdeps/linux/procopenfiles.c 2007-01-16 14:34:25.000000000 -0700 @@ -58,7 +58,8 @@ static void parse_file(const char *filename, LineParser parser, GHashTable *dict) { FILE *f; - char line[1024]; + char *line = NULL; + size_t size = 0; f = fopen(filename, "r"); @@ -67,15 +68,16 @@ parse_file(const char *filename, LinePar return; } + /* skip the first line */ - if(!fgets(line, sizeof line, f)) goto eof; + if (getline(&line, &size, f) == -1) + goto eof; - while(fgets(line, sizeof line, f)) - { + while (getline(&line, &size, f) != -1) parser(dict, line); - } eof: + free(line); fclose(f); } --- libgtop-2.14.3/sysdeps/linux/procmap.c.cve-2007-0235 2006-02-04 03:33:08.000000000 -0700 +++ libgtop-2.14.3/sysdeps/linux/procmap.c 2007-01-16 15:04:45.000000000 -0700 @@ -39,8 +39,8 @@ #define PROC_MAPS_FORMAT ((sizeof(void*) == 8) \ -? "%16lx-%16lx %4c %16lx %02hx:%02hx %lu%*[ ]%[^\n]\n" \ -: "%08lx-%08lx %4c %08lx %02hx:%02hx %lu%*[ ]%[^\n]\n") +? "%16lx-%16lx %4c %16lx %02hx:%02hx %lu%*[ ]%n" \ +: "%08lx-%08lx %4c %08lx %02hx:%02hx %lu%*[ ]%n") static const unsigned long _glibtop_sysdeps_proc_map = @@ -134,6 +134,8 @@ glibtop_get_proc_map_s (glibtop *server, FILE *maps; const char *filename; gboolean has_smaps; + char *line = NULL; + size_t line_size = 0; glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0); @@ -154,32 +156,28 @@ glibtop_get_proc_map_s (glibtop *server, while(TRUE) { - char line[1024]; - unsigned long perm = 0; - int rv; guint len; + int line_end; unsigned short dev_major, dev_minor; unsigned long start, end, offset, inode; char flags[4]; - char filename [GLIBTOP_MAP_FILENAME_LEN+1]; + char *filename; glibtop_map_entry *entry; - if (!fgets(line, sizeof line, maps)) + if (getline(&line, &line_size, maps) == -1) break; /* 8 arguments */ - rv = sscanf(line, PROC_MAPS_FORMAT, - &start, &end, flags, &offset, - &dev_major, &dev_minor, &inode, filename); - - if(rv == EOF || rv < 7) - break; - - if(rv == 7) /* no filename */ - filename[0] = '\0'; + if (sscanf(line, PROC_MAPS_FORMAT, + &start, &end, flags, &offset, + &dev_major, &dev_minor, &inode, &line_end) == EOF) + + g_assert(line_end < line_size); + filename = line + line_end; + g_strstrip(filename); /* Compute access permissions. */ @@ -219,6 +217,7 @@ glibtop_get_proc_map_s (glibtop *server, } + free(line); fclose (maps); buf->flags = _glibtop_sysdeps_proc_map;