Eric Blake wrote:
Daniel's patch works with gcc and CFLAGS containing -O (the
autoconf default), but fails with non-gcc or with other
CFLAGS (such as -g), since c-ctype.h declares c_isdigit as
a macro only for certain compilation settings.
* src/Makefile.am (libvirt_parthelper_LDFLAGS): Add gnulib
library, for when c_isdigit is not a macro.
* src/storage/parthelper.c (main): Avoid out-of-bounds
dereference, noticed by Jim Meyering.
---
change in v3: earlier code already guarantees that path is non-null
if we got this far, but not whether it is non-empty
src/Makefile.am | 2 +-
src/storage/parthelper.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 6bdf73c..2129960 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1035,13 +1035,13 @@ if WITH_STORAGE_DISK
if WITH_LIBVIRTD
libexec_PROGRAMS += libvirt_parthelper
libvirt_parthelper_SOURCES = $(STORAGE_HELPER_DISK_SOURCES)
libvirt_parthelper_LDFLAGS = $(WARN_LDFLAGS) $(COVERAGE_LDFLAGS)
libvirt_parthelper_LDADD = $(LIBPARTED_LIBS)
-libvirt_parthelper_CFLAGS = $(LIBPARTED_CFLAGS)
+libvirt_parthelper_CFLAGS = $(LIBPARTED_CFLAGS) ../gnulib/lib/libgnu.la
endif
endif
EXTRA_DIST += $(STORAGE_HELPER_DISK_SOURCES)
if WITH_LXC
diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c
index 28d88c9..ca74456 100644
--- a/src/storage/parthelper.c
+++ b/src/storage/parthelper.c
@@ -66,13 +66,13 @@ int main(int argc, char **argv)
} else if (argc != 2) {
fprintf(stderr, "syntax: %s DEVICE [-g]\n", argv[0]);
return 1;
}
path = argv[1];
- partsep = c_isdigit(path[strlen(path)-1]) ? "p" : "";
+ partsep = *path && c_isdigit(path[strlen(path)-1]) ? "p" :
"";
if ((dev = ped_device_get(path)) == NULL) {
fprintf(stderr, "unable to access device %s\n", path);
return 2;
}
Looks good.
ACK