summaryrefslogtreecommitdiffstats
path: root/sys-utils/ipcutils.c
diff options
context:
space:
mode:
authorRuediger Meier2016-03-18 12:49:17 +0100
committerKarel Zak2016-03-18 15:38:05 +0100
commit97fab80eaf210fb23e106a2cd4ec6dd998cd520d (patch)
treec1ab302bc82459d9858f934651cdb7cec449901f /sys-utils/ipcutils.c
parentswapon: rewrite control struct usage (diff)
downloadkernel-qcow2-util-linux-97fab80eaf210fb23e106a2cd4ec6dd998cd520d.tar.gz
kernel-qcow2-util-linux-97fab80eaf210fb23e106a2cd4ec6dd998cd520d.tar.xz
kernel-qcow2-util-linux-97fab80eaf210fb23e106a2cd4ec6dd998cd520d.zip
ipcs: make sure to parse whole lines for shm_data
We want to parse 16 columns _per_row_ without mixing them up. The existing code is unsafe for more or less columns and could even run into endless loops. This patch assures that we parse row-wise and really skip lines with columns != 16. Probably somehow we could have also done this with fscanf() only. Using fgets() additionally makes the code more easy to read and to improve later. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'sys-utils/ipcutils.c')
-rw-r--r--sys-utils/ipcutils.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/sys-utils/ipcutils.c b/sys-utils/ipcutils.c
index 400f00cf6..c763cde69 100644
--- a/sys-utils/ipcutils.c
+++ b/sys-utils/ipcutils.c
@@ -99,6 +99,7 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
{
FILE *f;
int i = 0, maxid;
+ char buf[BUFSIZ];
struct shm_data *p;
struct shmid_ds dummy;
@@ -111,8 +112,8 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
while (fgetc(f) != '\n'); /* skip header */
- while (feof(f) == 0) {
- if (fscanf(f,
+ while (fgets(buf, sizeof(buf), f) != NULL) {
+ if (sscanf(buf,
"%d %d %o %"SCNu64 " %u %u "
"%"SCNu64 " %u %u %u %u %"SCNi64 " %"SCNi64 " %"SCNi64
" %"SCNu64 " %"SCNu64 "\n",
@@ -132,7 +133,7 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
&p->shm_ctim,
&p->shm_rss,
&p->shm_swp) != 16)
- continue;
+ continue; /* ivalid line, skipped */
if (id > -1) {
/* ID specified */