libmultipath: use asprintf() to allocate prefixed_uuid
Benjamin Marzinski
maintainerPATCH 1/1 libmultipath: use asprintf() to allocate prefixed_uuid
gcc 12.0.1 failed building libmultipath due to a format-overflow false positive on 32-bit architectures. This isn't so surprising as format-overflow=2 is very aggressive in the assumptions it makes about the arguments. Here, it assumes that mpp->wwid could take up all the space that a pointer could point to, even if I add code to this function to explicitly null terminate mpp->wwid to fit in WWID_SIZE.
To avoid this and simplify the function, switch from using calloc() and sprintf() to just using asprintf().
For reference, the gcc build error that this fixes is:
devmapper.c: In function 'dm_addmap.constprop.0':
devmapper.h:27:21: error: '%s' directive writing up to 2147483644 bytes into a region of size 2147483641 [-Werror=format-overflow=]
27 | #define UUID_PREFIX "mpath-"
| ^~~~~~~~
devmapper.c:484:53: note: format string is defined here
484 | sprintf(prefixed_uuid, UUID_PREFIX "%s", mpp->wwid);
| ^~
--- libmultipath/devmapper.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
libmultipath/devmapper.c +1 -4
@@ -473,14 +473,11 @@ dm_addmap (int task, const char *target, struct multipath *mpp,dm_task_set_ro (dmt);if (task ==DM_DEVICE_CREATE ) { - prefixed_uuid =calloc (1 ,UUID_PREFIX_LEN + -strlen (mpp->wwid) +1 ); -if (!prefixed_uuid) { +if (asprintf (&prefixed_uuid,UUID_PREFIX "%s" , mpp->wwid) <0 ) {condlog (0 ,"cannot create prefixed uuid : %s" ,strerror (errno)); goto addout; } -sprintf (prefixed_uuid,UUID_PREFIX "%s" , mpp->wwid);if (!dm_task_set_uuid (dmt, prefixed_uuid)) goto freeout;dm_task_skip_lockfs (dmt);
Signature · 6 lines
2.17.2 -- dm-devel mailing list [email protected] https://listman.redhat.com/mailman/listinfo/dm-devel
Quoted 9 lines · Benjamin Marzinski
gcc 12.0.1 failed building libmultipath due to a format-overflow false
positive on 32-bit architectures. This isn't so surprising as format-overflow=2 is very aggressive in the assumptions it makes about
the arguments. Here, it assumes thatmpp->wwidcould take up all the space that a pointer could point to, even if I add code to this function
to explicitly null terminatempp->wwidto fit inWWID_SIZE.
This sounds like a bug in gcc which should be reported.
Quoted 14 lines
To avoid this and simplify the function, switch from using
calloc()andsprintf()to just usingasprintf().For reference, the gcc build error that this fixes is:
devmapper.c: In function 'dm_addmap.constprop.0':
devmapper.h:27:21: error: '%s' directive writing up to 2147483644 bytes into a region of size 2147483641 [-Werror=format-overflow=] 27 | #defineUUID_PREFIX"mpath-"
| ^~~~~~~~
devmapper.c:484:53: note: format string is defined here 484 | sprintf(prefixed_uuid,UUID_PREFIX"%s", mpp-
Quoted 4 lines
Quoted 1 line
wwid);
| ^~
Signed-off-by Benjamin Marzinski <[email protected]>
Quoted 18 lines
---
libmultipath/devmapper.c | 5 +----1 file changed, 1 insertion(+), 4 deletions(-)libmultipath/devmapper.c +0
-0@@ -473,14 +473,11 @@ dm_addmap (int task, const char *target, structmultipath *mpp, dm_task_set_ro(dmt);
if (task ==DM_DEVICE_CREATE) {
- prefixed_uuid = calloc(1,UUID_PREFIX_LEN+ -strlen(mpp->wwid)+ 1); - if (!prefixed_uuid) {
+ if (asprintf(&prefixed_uuid,UUID_PREFIX"%s", mpp-Quoted 1 line
wwid) < 0) {
Quoted 9 lines
condlog(0, "cannot create prefixed uuid :
%s",
strerror(errno));
goto addout;
}
- sprintf(prefixed_uuid,UUID_PREFIX"%s",mpp->wwid); if (!dm_task_set_uuid(dmt,prefixed_uuid)) goto freeout;dm_task_skip_lockfs(dmt);
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Quoted 12 lines · Martin Wilck
Quoted 10 lines · Benjamin Marzinski
gcc 12.0.1 failed building libmultipath due to a format-overflow false
positive on 32-bit architectures. This isn't so surprising as format-overflow=2 is very aggressive in the assumptions it makes about
the arguments. Here, it assumes thatmpp->wwidcould take up all the
space that a pointer could point to, even if I add code to this function
to explicitly null terminatempp->wwidto fit inWWID_SIZE.
Quoted 1 line
This sounds like a bug in gcc which should be reported.
... and that bug exists already:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104119
Martin
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel