Skip to contentSkip to conversation

libmultipath: fix condlog NULL argument in uevent_get_env_var

PATCH In review Benjamin Marzinski 2 participants 2 messages Jun 4, 2020 – Jun 5, 2020 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

PATCH 1/1 libmultipath: fix condlog NULL argument in uevent_get_env_var

uevent_get_env_var() could call condlog with p == NULL. On gcc 10, this triggers warnings like:

In file included from uevent.c:47:
In function 'uevent_get_env_var',
inlined from 'uevent_get_wwid' at uevent.c:170:8:
debug.h:13:2: error: '%s' directive argument is null [-Werror=format-overflow=]

   13 |  dlog(logsink, prio, fmt "\n", ##args)
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uevent.c:132:2: note: in expansion of macro 'condlog'
  132 |  condlog(4, "%s: %s -> '%s'", __func__, attr, p);
      |  ^~~~~~~

uevent.c: In function 'uevent_get_wwid':
uevent.c:132:25: note: format string is defined here
132 | condlog(4, "%s: %s -> '%s'", __func__, attr, p);
| ^~

If p is NULL, use "(null)" instead.

---
 libmultipath/uevent.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/uevent.c +1 -1
index d38e8a7f..e0d13b11 100644
@@ -129,7 +129,7 @@ static const char* uevent_get_env_var(const struct uevent *uev,
 		}
 	}
 
-	condlog(4, "%s: %s -> '%s'", __func__, attr, p);
+	condlog(4, "%s: %s -> '%s'", __func__, attr, p ?: "(null)");
 	return p;
 
 invalid:
Signature · 1 line
2.17.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Benjamin Marzinski

uevent_get_env_var() could call condlog with p == NULL. On gcc 10, this triggers warnings like:

In file included from uevent.c:47:
In function 'uevent_get_env_var',
inlined from 'uevent_get_wwid' at uevent.c:170:8:
debug.h:13:2: error: '%s' directive argument is null [-Werror=format-overflow=]

   13 |  dlog(logsink, prio, fmt "\n", ##args)
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uevent.c:132:2: note: in expansion of macro 'condlog'
  132 |  condlog(4, "%s: %s -> '%s'", __func__, attr, p);
      |  ^~~~~~~

uevent.c: In function 'uevent_get_wwid':
uevent.c:132:25: note: format string is defined here
132 | condlog(4, "%s: %s -> '%s'", __func__, attr, p);
| ^~

Quoted 6 lines

If p is NULL, use "(null)" instead.

---
 libmultipath/uevent.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)