On Tue, Sep 04, 2012 at 10:13:06AM +0200, Thomas Anders wrote:
> I'd argue for an additional comment in the code similar to the
> explanation in your mail.

Extended version attached

/Niels

-- 
Niels Baggesen - @home - Ã…rhus - Denmark - n...@users.sourceforge.net
The purpose of computing is insight, not numbers   ---   R W Hamming
diff --git a/agent/mibgroup/hardware/fsys/fsys_getfsstats.c 
b/agent/mibgroup/hardware/fsys/fsys_getfsstats.c
index 1eda986..8e9468b 100644
--- a/agent/mibgroup/hardware/fsys/fsys_getfsstats.c
+++ b/agent/mibgroup/hardware/fsys/fsys_getfsstats.c
@@ -157,7 +157,14 @@ netsnmp_fsys_arch_load( void )
         entry->units = stats[i].f_bsize;    /* or f_frsize */
         entry->size  = stats[i].f_blocks;
         entry->used  = (stats[i].f_blocks - stats[i].f_bfree);
-        entry->avail = stats[i].f_bavail;
+        /* entry->avail is currently unsigned, so protect against negative
+         * values!
+         * This should be changed to a signed field.
+         */
+        if (stats[i].f_bavail < 0)
+            entry->avail = 0;
+        else
+            entry->avail = stats[i].f_bavail;
         entry->inums_total = stats[i].f_files;
         entry->inums_avail = stats[i].f_ffree;
 
diff --git a/agent/mibgroup/hardware/fsys/fsys_mntent.c 
b/agent/mibgroup/hardware/fsys/fsys_mntent.c
index b9e6b64..74176ca 100644
--- a/agent/mibgroup/hardware/fsys/fsys_mntent.c
+++ b/agent/mibgroup/hardware/fsys/fsys_mntent.c
@@ -241,7 +241,14 @@ netsnmp_fsys_arch_load( void )
         entry->units =  stat_buf.NSFS_SIZE;
         entry->size  =  stat_buf.f_blocks;
         entry->used  = (stat_buf.f_blocks - stat_buf.f_bfree);
-        entry->avail =  stat_buf.f_bavail;
+        /* entry->avail is currently unsigned, so protect against negative
+         * values!
+         * This should be changed to a signed field.
+         */
+        if (stat_buf.f_bavail < 0)
+            entry->avail = 0;
+        else
+            entry->avail =  stat_buf.f_bavail;
         entry->inums_total = stat_buf.f_files;
         entry->inums_avail = stat_buf.f_ffree;
         netsnmp_fsys_calculate32(entry);
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to