* [PATCH 0/2] ipcs: more robust and compatible /proc parsing
@ 2016-03-18 11:49 Ruediger Meier
2016-03-18 11:49 ` [PATCH 1/2] ipcs: make sure to parse whole lines for shm_data Ruediger Meier
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Ruediger Meier @ 2016-03-18 11:49 UTC (permalink / raw)
To: util-linux
From: Ruediger Meier <ruediger.meier@ga-group.nl>
If this looks ok for shm then we could also add similar patches for
sem and msg.
Ruediger Meier (2):
ipcs: make sure to parse whole lines for shm_data
ipcs: --shmems, upward/backward compatibility
sys-utils/ipcutils.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
--
1.8.4.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] ipcs: make sure to parse whole lines for shm_data
2016-03-18 11:49 [PATCH 0/2] ipcs: more robust and compatible /proc parsing Ruediger Meier
@ 2016-03-18 11:49 ` Ruediger Meier
2016-03-18 11:49 ` [PATCH 2/2] ipcs: --shmems, upward/backward compatibility Ruediger Meier
2016-03-18 13:48 ` [PATCH 0/2] ipcs: more robust and compatible /proc parsing Karel Zak
2 siblings, 0 replies; 6+ messages in thread
From: Ruediger Meier @ 2016-03-18 11:49 UTC (permalink / raw)
To: util-linux
From: Ruediger Meier <ruediger.meier@ga-group.nl>
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>
---
sys-utils/ipcutils.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/sys-utils/ipcutils.c b/sys-utils/ipcutils.c
index 400f00c..c763cde 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 */
--
1.8.4.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] ipcs: --shmems, upward/backward compatibility
2016-03-18 11:49 [PATCH 0/2] ipcs: more robust and compatible /proc parsing Ruediger Meier
2016-03-18 11:49 ` [PATCH 1/2] ipcs: make sure to parse whole lines for shm_data Ruediger Meier
@ 2016-03-18 11:49 ` Ruediger Meier
2016-03-18 13:48 ` [PATCH 0/2] ipcs: more robust and compatible /proc parsing Karel Zak
2 siblings, 0 replies; 6+ messages in thread
From: Ruediger Meier @ 2016-03-18 11:49 UTC (permalink / raw)
To: util-linux
From: Ruediger Meier <ruediger.meier@ga-group.nl>
Re-add backward compatibility which got lost in 058e8154.
Initializing unknown struct members to 0xdead is similar to
the fallback.
For upward compatibility ignore columns > 16 but not the whole
line (in case the kernel would add more columns in future).
Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
sys-utils/ipcutils.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/sys-utils/ipcutils.c b/sys-utils/ipcutils.c
index c763cde..349e855 100644
--- a/sys-utils/ipcutils.c
+++ b/sys-utils/ipcutils.c
@@ -113,6 +113,9 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
while (fgetc(f) != '\n'); /* skip header */
while (fgets(buf, sizeof(buf), f) != NULL) {
+ /* scan for the first 14-16 columns (e.g. Linux 2.6.32 has 14) */
+ p->shm_rss = 0xdead;
+ p->shm_swp = 0xdead;
if (sscanf(buf,
"%d %d %o %"SCNu64 " %u %u "
"%"SCNu64 " %u %u %u %u %"SCNi64 " %"SCNi64 " %"SCNi64
@@ -132,7 +135,7 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
&p->shm_dtim,
&p->shm_ctim,
&p->shm_rss,
- &p->shm_swp) != 16)
+ &p->shm_swp) < 14)
continue; /* ivalid line, skipped */
if (id > -1) {
--
1.8.4.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] ipcs: more robust and compatible /proc parsing
2016-03-18 11:49 [PATCH 0/2] ipcs: more robust and compatible /proc parsing Ruediger Meier
2016-03-18 11:49 ` [PATCH 1/2] ipcs: make sure to parse whole lines for shm_data Ruediger Meier
2016-03-18 11:49 ` [PATCH 2/2] ipcs: --shmems, upward/backward compatibility Ruediger Meier
@ 2016-03-18 13:48 ` Karel Zak
2016-03-18 14:03 ` Ruediger Meier
2 siblings, 1 reply; 6+ messages in thread
From: Karel Zak @ 2016-03-18 13:48 UTC (permalink / raw)
To: Ruediger Meier; +Cc: util-linux
On Fri, Mar 18, 2016 at 12:49:16PM +0100, Ruediger Meier wrote:
> From: Ruediger Meier <ruediger.meier@ga-group.nl>
>
> If this looks ok for shm then we could also add similar patches for
> sem and msg.
Seems good, I'll wait for complete set of the patches, ok?
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] ipcs: more robust and compatible /proc parsing
2016-03-18 13:48 ` [PATCH 0/2] ipcs: more robust and compatible /proc parsing Karel Zak
@ 2016-03-18 14:03 ` Ruediger Meier
2016-03-18 14:38 ` Karel Zak
0 siblings, 1 reply; 6+ messages in thread
From: Ruediger Meier @ 2016-03-18 14:03 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On Friday 18 March 2016, Karel Zak wrote:
> On Fri, Mar 18, 2016 at 12:49:16PM +0100, Ruediger Meier wrote:
> > From: Ruediger Meier <ruediger.meier@ga-group.nl>
> >
> > If this looks ok for shm then we could also add similar patches for
> > sem and msg.
>
> Seems good, I'll wait for complete set of the patches, ok?
For msg and sem we don't have compatibility problems or bugs in real
life but only these _potential_ fscanf issues. Not so important for
2.28.
I would like to do that later in a project wide scanf review but without
hurry.
cu,
Rudi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] ipcs: more robust and compatible /proc parsing
2016-03-18 14:03 ` Ruediger Meier
@ 2016-03-18 14:38 ` Karel Zak
0 siblings, 0 replies; 6+ messages in thread
From: Karel Zak @ 2016-03-18 14:38 UTC (permalink / raw)
To: Ruediger Meier; +Cc: util-linux
On Fri, Mar 18, 2016 at 03:03:32PM +0100, Ruediger Meier wrote:
> On Friday 18 March 2016, Karel Zak wrote:
> > On Fri, Mar 18, 2016 at 12:49:16PM +0100, Ruediger Meier wrote:
> > > From: Ruediger Meier <ruediger.meier@ga-group.nl>
> > >
> > > If this looks ok for shm then we could also add similar patches for
> > > sem and msg.
> >
> > Seems good, I'll wait for complete set of the patches, ok?
>
> For msg and sem we don't have compatibility problems or bugs in real
> life but only these _potential_ fscanf issues. Not so important for
> 2.28.
>
> I would like to do that later in a project wide scanf review but without
> hurry.
OK, Applied, thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-03-18 14:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-18 11:49 [PATCH 0/2] ipcs: more robust and compatible /proc parsing Ruediger Meier
2016-03-18 11:49 ` [PATCH 1/2] ipcs: make sure to parse whole lines for shm_data Ruediger Meier
2016-03-18 11:49 ` [PATCH 2/2] ipcs: --shmems, upward/backward compatibility Ruediger Meier
2016-03-18 13:48 ` [PATCH 0/2] ipcs: more robust and compatible /proc parsing Karel Zak
2016-03-18 14:03 ` Ruediger Meier
2016-03-18 14:38 ` Karel Zak
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.