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:
Benoît Dejean
2007-01-14 18:09:56 +00:00
committed by Benoît Dejean
parent c9385972bd
commit e156172e7c
3 changed files with 31 additions and 20 deletions

View File

@@ -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, LineParser parser, GHashTable *dict)
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);
}
eof:
free(line);
fclose(f);
}