Fix get_from_pipe potentially reading more bytes than its buffer size

This commit is contained in:
ToMe25
2023-08-04 11:09:12 +02:00
committed by Robert Roth
parent 306f5d0c8f
commit 079b9e17c5
5 changed files with 8 additions and 9 deletions

1
.gitignore vendored
View File

@@ -58,6 +58,7 @@ doc/texinfo.tex
doc/version.texi
examples/affinity
examples/df
examples/disk
examples/diskio
examples/first
examples/free

View File

@@ -11,7 +11,7 @@ AM_LDFLAGS = $(LIBGTOP_EXTRA_LIBS)
noinst_PROGRAMS = first second pprint procargs df netlist \
mountlist procmap netload sysdeps timings \
openfiles smp proclist free wd affinity diskio sysinfo
openfiles smp proclist free wd affinity disk diskio sysinfo
first_SOURCES = first.c
first_LDADD = $(top_builddir)/lib/libgtop-2.0.la

View File

@@ -235,7 +235,7 @@ glibtop_get_disk_s (glibtop *server, glibtop_disk *buf)
file_to_buffer (server, buffer, sizeof buffer, FILENAME);
get_from_pipe (map_buffer, CMD_PIPE);
get_from_pipe (map_buffer, STAT_BUFSIZ, CMD_PIPE);
/*
* GLOBAL

View File

@@ -58,17 +58,15 @@ skip_token (const char *p)
void
get_from_pipe (char *buffer, const char *cmd)
get_from_pipe (char *buffer, const size_t bufsiz, const char *cmd)
{
FILE* fp;
long psize;
fp = popen (cmd, "r");
fseek (fp, 0, SEEK_END);
psize = ftell (fp);
fseek (fp, 0, SEEK_SET);
fread(buffer,1,psize,fp);
size_t psize = fread(buffer,1,bufsiz,fp);
if (psize == bufsiz)
g_warning("Read bufsiz bytes, there may be more");
pclose (fp);
}

View File

@@ -62,7 +62,7 @@ skip_line (const char *p)
}
void
get_from_pipe (char *buffer, const char *cmd);
get_from_pipe (char *buffer, const size_t bufsiz, const char *cmd);
/*
* Smart strtoul which handles binary suffixes