/proc/<pid>/stat was improperly parsed. When skipping a field, a while
loop is used:

        while ( ' ' != *(cp++))
            ;

After the execution of the while loop, `*cp` is a non-space
character. There is no need to increment `cp` again. Moreover, the
loop to skip 11 elements only skipped 10 elements. Same for the loop
that needed to skip 9 elements: only 8 elements were skipped.

Signed-off-by: Vincent Bernat <[email protected]>
---
 .../host/data_access/swrun_procfs_status.c         |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/agent/mibgroup/host/data_access/swrun_procfs_status.c 
b/agent/mibgroup/host/data_access/swrun_procfs_status.c
index a9aa2d8..bca98fa 100644
--- a/agent/mibgroup/host/data_access/swrun_procfs_status.c
+++ b/agent/mibgroup/host/data_access/swrun_procfs_status.c
@@ -183,21 +183,18 @@ netsnmp_arch_swrun_container_load( netsnmp_container 
*container, u_int flags)
         default:   entry->hrSWRunStatus = HRSWRUNSTATUS_INVALID;
                    break;
         }
-        for (i=10; i; i--) {   /* Skip STATUS + 10 fields */
+        for (i=11; i; i--) {   /* Skip STATUS + 10 fields */
             while (' ' != *(cp++))
                 ;
-            cp++;
         }
         entry->hrSWRunPerfCPU  = atoi( cp );   /*  utime */
-        while ( ' ' != *(cp++))
+        while ( ' ' != *(cp++))                       /* Skip utime */
             ;
-        cp++;                             /* Skip utime */
         entry->hrSWRunPerfCPU += atoi( cp );   /* +stime */
 
-        for (i=8; i; i--) {   /* Skip stime + 8 fields */
+        for (i=9; i; i--) {   /* Skip stime + 8 fields */
             while (' ' != *(cp++))
                 ;
-            cp++;
         }
         entry->hrSWRunPerfMem  = atoi( cp );   /*  rss */
         entry->hrSWRunPerfMem *= (getpagesize()/1024);  /* in kB */
-- 
1.7.8.3


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to