From 35f543f7f2ef1e6f5e7a73144103bf29f8de4594 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Fri, 25 Sep 2009 11:51:25 +0200 Subject: [PATCH] Fixup strip trailing whitespaces for getuid return value 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 '' if the getuid was found to be empty. References: bnc#542085 Signed-off-by: Hannes Reinecke --- libmultipath/discovery.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 843630b..dde876f 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -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' ? "" : pp->wwid); return 0; } -- 2.7.4