[openib-general] RE: [patch] userspace/management/diags/src/sminfo.c - cmdline processing fix

Hal Rosenstock halr at voltaire.com
Tue Jan 17 06:20:22 PST 2006


Hi Sasha,
 
Thanks. Applied.
 
I would welcome such a patch.
 
-- Hal

________________________________

From: Sasha Khapyorsky [mailto:sashak at voltaire.com]
Sent: Tue 1/17/2006 5:10 AM
To: Hal Rosenstock
Cc: openib
Subject: [patch] userspace/management/diags/src/sminfo.c - cmdline processing fix



Hello Hal,

There is small bug in sminfo's cmdline processing, this will segfault
when option argument is missing (like 'sminfo -a'). The "fast and dirty"
fix is inlined.

The same problem exists with most diag tools, so I think we need to
rework AGRBEGIN { ... } ARGEND stuff (actually remove it from
libibcommon since it is used by diag tools only). I can do it if there
are no objections.

Regards,
Sasha.


This fast fix for invalid ARGF() usage in sminfo.c.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>

Index: diags/src/sminfo.c
===================================================================
--- diags/src/sminfo.c  (revision 5017)
+++ diags/src/sminfo.c  (working copy)
@@ -49,6 +49,8 @@

 #define IBERROR(fmt, args...)  iberror(__FUNCTION__, fmt, ## args)

+#define SAFE_ARGF() (*(argv+1) ? ARGF() : ( usage(), NULL ) )
+
 static void
 iberror(const char *fn, char *msg, ...)
 {
@@ -116,10 +118,10 @@

        ARGBEGIN {
        case 'C':
-               ca = ARGF();
+               ca = SAFE_ARGF();
                break;
        case 'P':
-               ca_port = strtoul(ARGF(), 0, 0);
+               ca_port = strtoul(SAFE_ARGF(), 0, 0);
                break;
        case 'd':
                ibdebug++;
@@ -137,17 +139,17 @@
                dest_type = IB_DEST_GUID;
                break;
        case 't':
-               timeout = strtoul(ARGF(), 0, 0);
+               timeout = strtoul(SAFE_ARGF(), 0, 0);
                madrpc_set_timeout(timeout);
                break;
        case 'a':
-               act = strtoul(ARGF(), 0, 0);
+               act = strtoul(SAFE_ARGF(), 0, 0);
                break;
        case 's':
-               state = strtoul(ARGF(), 0, 0);
+               state = strtoul(SAFE_ARGF(), 0, 0);
                break;
        case 'p':
-               prio = strtoul(ARGF(), 0, 0);
+               prio = strtoul(SAFE_ARGF(), 0, 0);
                break;
        case 'V':
                fprintf(stderr, "%s %s\n", argv0, get_build_version() );





More information about the general mailing list