On Wed, 2024-07-10 at 18:54 -0400, Benjamin Marzinski wrote: > On Tue, Jul 09, 2024 at 11:39:12PM +0200, Martin Wilck wrote: > > Use sscanf to make the parsing of the UUID more robust. > > > > Signed-off-by: Martin Wilck <mwilck@xxxxxxxx> > > --- > > libmultipath/devmapper.c | 17 +++++++---------- > > 1 file changed, 7 insertions(+), 10 deletions(-) > > > > diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c > > index 56157af..d62a7dd 100644 > > --- a/libmultipath/devmapper.c > > +++ b/libmultipath/devmapper.c > > @@ -846,23 +846,20 @@ int dm_get_uuid(const char *name, char *uuid, > > int uuid_len) > > > > static int is_mpath_part(const char *part_name, const char > > *map_name) > > { > > - char *p; > > - char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN]; > > + char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN], c; > > + int np, nc; > > > > if (dm_get_dm_uuid(part_name, part_uuid) != DMP_OK) > > return 0; > > > > + if (2 != sscanf(part_uuid, "part%d-%n" UUID_PREFIX "%c", > > &np, &nc, &c) > > we should probably use "part%u-%n" so we can't match a "-" before the > number. That doesn't work, %u accepts negative numbers, too (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf) That's why I use int and check whether the result is positive. Martin