Fixed stack overflow in proc_map. Switched to Glibc getline because fgets
2007-01-14 Benoît Dejean <benoit@placenet.org> * procmap.c: (glibtop_get_proc_map_s): * procopenfiles.c: (parse_file): Fixed stack overflow in proc_map. Switched to Glibc getline because fgets gets fooled by long lines. Closes #396477. svn path=/trunk/; revision=2546
This commit is contained in:
committed by
Benoît Dejean
parent
c9385972bd
commit
e156172e7c
@@ -1,3 +1,13 @@
|
|||||||
|
2007-01-14 Benoît Dejean <benoit@placenet.org>
|
||||||
|
|
||||||
|
* procmap.c: (glibtop_get_proc_map_s):
|
||||||
|
* procopenfiles.c: (parse_file):
|
||||||
|
|
||||||
|
Fixed stack overflow in proc_map.
|
||||||
|
Switched to Glibc getline because fgets gets fooled by long
|
||||||
|
lines.
|
||||||
|
Closes #396477.
|
||||||
|
|
||||||
2007-01-11 Benoît Dejean <benoit@placenet.org>
|
2007-01-11 Benoît Dejean <benoit@placenet.org>
|
||||||
|
|
||||||
* glibtop_private.c: (get_scaled):
|
* glibtop_private.c: (get_scaled):
|
||||||
|
@@ -38,7 +38,7 @@
|
|||||||
#define SMAPS_FILE "/proc/%u/smaps"
|
#define SMAPS_FILE "/proc/%u/smaps"
|
||||||
|
|
||||||
|
|
||||||
#define PROC_MAPS_FORMAT "%16llx-%16llx %4c %16llx %02hx:%02hx %llu%*[ ]%[^\n]\n"
|
#define PROC_MAPS_FORMAT "%16llx-%16llx %4c %16llx %02hx:%02hx %llu%*[ ]%n"
|
||||||
|
|
||||||
|
|
||||||
static const unsigned long _glibtop_sysdeps_proc_map =
|
static const unsigned long _glibtop_sysdeps_proc_map =
|
||||||
@@ -132,6 +132,8 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
|||||||
FILE *maps;
|
FILE *maps;
|
||||||
const char *filename;
|
const char *filename;
|
||||||
gboolean has_smaps;
|
gboolean has_smaps;
|
||||||
|
char *line = NULL;
|
||||||
|
size_t line_size = 0;
|
||||||
|
|
||||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
|
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
|
||||||
|
|
||||||
@@ -152,32 +154,28 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
|||||||
|
|
||||||
while(TRUE)
|
while(TRUE)
|
||||||
{
|
{
|
||||||
char line[1024];
|
|
||||||
|
|
||||||
unsigned long perm = 0;
|
unsigned long perm = 0;
|
||||||
int rv;
|
|
||||||
guint len;
|
guint len;
|
||||||
|
int line_end;
|
||||||
|
|
||||||
unsigned short dev_major, dev_minor;
|
unsigned short dev_major, dev_minor;
|
||||||
guint64 start, end, offset, inode;
|
guint64 start, end, offset, inode;
|
||||||
char flags[4];
|
char flags[4];
|
||||||
char filename [GLIBTOP_MAP_FILENAME_LEN+1];
|
char *filename;
|
||||||
|
|
||||||
glibtop_map_entry *entry;
|
glibtop_map_entry *entry;
|
||||||
|
|
||||||
if (!fgets(line, sizeof line, maps))
|
if (getline(&line, &line_size, maps) == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* 8 arguments */
|
/* 8 arguments */
|
||||||
rv = sscanf(line, PROC_MAPS_FORMAT,
|
if (sscanf(line, PROC_MAPS_FORMAT,
|
||||||
&start, &end, flags, &offset,
|
&start, &end, flags, &offset,
|
||||||
&dev_major, &dev_minor, &inode, filename);
|
&dev_major, &dev_minor, &inode, &line_end) != 7)
|
||||||
|
|
||||||
if(rv == EOF || rv < 7)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if(rv == 7) /* no filename */
|
filename = line + line_end;
|
||||||
filename[0] = '\0';
|
g_strstrip(filename);
|
||||||
|
|
||||||
/* Compute access permissions. */
|
/* Compute access permissions. */
|
||||||
|
|
||||||
@@ -217,6 +215,7 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(line);
|
||||||
fclose (maps);
|
fclose (maps);
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_proc_map;
|
buf->flags = _glibtop_sysdeps_proc_map;
|
||||||
|
@@ -58,7 +58,8 @@ static void
|
|||||||
parse_file(const char *filename, LineParser parser, GHashTable *dict)
|
parse_file(const char *filename, LineParser parser, GHashTable *dict)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char line[1024];
|
char *line = NULL;
|
||||||
|
size_t size = 0;
|
||||||
|
|
||||||
f = fopen(filename, "r");
|
f = fopen(filename, "r");
|
||||||
|
|
||||||
@@ -67,15 +68,16 @@ parse_file(const char *filename, LineParser parser, GHashTable *dict)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* skip the first line */
|
|
||||||
if(!fgets(line, sizeof line, f)) goto eof;
|
|
||||||
|
|
||||||
while(fgets(line, sizeof line, f))
|
/* skip the first line */
|
||||||
{
|
if (getline(&line, &size, f) == -1)
|
||||||
|
goto eof;
|
||||||
|
|
||||||
|
while (getline(&line, &size, f) != -1)
|
||||||
parser(dict, line);
|
parser(dict, line);
|
||||||
}
|
|
||||||
|
|
||||||
eof:
|
eof:
|
||||||
|
free(line);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user