On 24 March 2010 07:56, Magnus Fromreide <[email protected]> wrote:
>> 1) Latch disk statistics: no / 54x only / both 54x and 52x
>
> both -1
>
> Adds warnings about silly compares on 32 bit platforms.
> Adds magic constant instead of using INT32_MAX
> Works differently on 32 and 64 bit if the multiplication above the
> comparision overflows.
>
> I think the following would be a better pattern to follow for the checks:
>
> if (vfs.f_blocks > (INT32_MAX / multiplier))
> long_ret = INT32_MAX;
> else
> long_ret = vfs.f_blocks * multiplier;
In response to these comments, I've drafted a revised version
of this patch (attached), which uses the comparison code
structure that you suggest.
It also uses INT32_MAX where available (but doesn't rely
on this necessarily being defined)
Does this version address your concerns?
Dave
Index: agent/mibgroup/ucd-snmp/disk.c
===================================================================
--- agent/mibgroup/ucd-snmp/disk.c (revision 18394)
+++ agent/mibgroup/ucd-snmp/disk.c (working copy)
@@ -163,6 +163,13 @@
int minpercent;
};
+#ifdef INT32_MAX
+#define NS_INT32_MAX INT32_MAX
+#else
+#define NS_INT32_MAX 0x7fffffff
+#endif
+
+
int numdisks;
int allDisksIncluded = 0;
int maxdisks = 0;
@@ -751,7 +758,7 @@
#endif
avail = (long)(vfs.f_bavail * multiplier);
iserror = (disks[disknum].minimumspace >= 0 ?
- avail < disks[disknum].minimumspace :
+ vfs.f_bavail < (disks[disknum].minimumspace/multiplier) :
100 - percent <= disks[disknum].minpercent) ? 1 : 0;
#if defined(STRUCT_STATVFS_HAS_F_FILES) || defined STRUCT_STATFS_HAS_F_FAVAIL
percent_inode = vfs.f_favail <= 0 ? 100 :
@@ -767,12 +774,22 @@
#endif /* defined(STRUCT_STATVFS_HAS_F_FILES) */
switch (vp->magic) {
case DISKTOTAL:
- long_ret = (long)(vfs.f_blocks * multiplier);
+ if ( vfs.f_blocks > ( NS_INT32_MAX / multiplier )
+ long_ret = NS_INT32_MAX;
+ else
+ long_ret = (long)(vfs.f_blocks * multiplier);
return ((u_char *) (&long_ret));
case DISKAVAIL:
- return ((u_char *) (&avail));
+ if ( vfs.f_bavail > ( NS_INT32_MAX / multiplier )
+ long_ret = NS_INT32_MAX;
+ else
+ long_ret = (long)(vfs.f_bavail * multiplier);
+ return ((u_char *) (&long_ret));
case DISKUSED:
- long_ret = (long)((vfs.f_blocks - vfs.f_bfree) * multiplier);
+ if ( (vfs.f_blocks - vfs.f_bfree) > ( NS_INT32_MAX / multiplier )
+ long_ret = NS_INT32_MAX;
+ else
+ long_ret = (long)((vfs.f_blocks - vfs.f_bfree) * multiplier);
return ((u_char *) (&long_ret));
case DISKPERCENT:
long_ret = percent;
@@ -844,13 +861,22 @@
: 100 - percent <= disks[disknum].minpercent) ? 1 : 0;
switch (vp->magic) {
case DISKTOTAL:
- long_ret = (long)(totalblks * multiplier);
+ if ( totalblks > ( NS_INT32_MAX / multiplier )
+ long_ret = NS_INT32_MAX;
+ else
+ long_ret = (long)(totalblks * multiplier);
return ((u_char *) (&long_ret));
case DISKAVAIL:
- long_ret = (long)(avail * multiplier);
+ if ( avail > ( NS_INT32_MAX / multiplier )
+ long_ret = NS_INT32_MAX;
+ else
+ long_ret = (long)(avail * multiplier);
return ((u_char *) (&long_ret));
case DISKUSED:
- long_ret = (long)(used * multiplier);
+ if ( used > ( NS_INT32_MAX / multiplier )
+ long_ret = NS_INT32_MAX;
+ else
+ long_ret = (long)(used * multiplier);
return ((u_char *) (&long_ret));
case DISKPERCENT:
long_ret = percent;
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders