Fixup strip trailing whitespaces for getuid return value
authorHannes Reinecke <hare@suse.de>
Fri, 25 Sep 2009 09:51:25 +0000 (11:51 +0200)
committerHannes Reinecke <hare@suse.de>
Sun, 15 May 2011 10:45:12 +0000 (12:45 +0200)
The getuid callout might return a wwid with trailing
spaces (or containing only spaces). The existing
fixup code will only work if the getuid callout
returns a wwid with the entire space used up.
So fixup this and also update the logging output
to correctly state '<empty>' if the getuid was
found to be empty.

References: bnc#542085

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/discovery.c

index 843630b89ab754fe98dcaa6b3befc33d3fd6c6b5..dde876fad810effb604eed1c65f18379f74d19b1 100644 (file)
@@ -837,8 +837,7 @@ get_prio (struct path * pp)
 static int
 get_uid (struct path * pp)
 {
-       char buff[CALLOUT_MAX_SIZE];
-       int i;
+       char buff[CALLOUT_MAX_SIZE], *c;
 
        if (!pp->getuid)
                select_getuid(pp);
@@ -852,12 +851,14 @@ get_uid (struct path * pp)
                return 1;
        }
        /* Strip any trailing blanks */
-       i = WWID_SIZE - 1;
-       while (i > 0 && pp->wwid[i] == ' ') {
-               pp->wwid[i] = '\0';
-               i--;
-       }
-       condlog(3, "%s: uid = %s (callout)", pp->dev ,pp->wwid);
+       c = strchr(pp->wwid, '\0');
+       c--;
+       while (c && c >= pp->wwid && *c == ' ') {
+               *c = '\0';
+               c--;
+       }
+       condlog(3, "%s: uid = %s (callout)", pp->dev,
+               *pp->wwid == '\0' ? "<empty>" : pp->wwid);
        return 0;
 }