[libvirt] [PATCH] Avoid passing NULL to printf %s specifier

# HG changeset patch # User john.levon@sun.com # Date 1232032750 28800 # Node ID 0335828806b5b3855c8eeaee31446a7bd0c02974 # Parent e542223a4c52d978d4507de709f50885920a5b44 Avoid passing NULL to printf %s specifier This is non-portable. Signed-off-by: John Levon <john.levon@sun.com> diff --git a/src/internal.h b/src/internal.h --- a/src/internal.h +++ b/src/internal.h @@ -7,6 +7,7 @@ #include <errno.h> #include <limits.h> +#include <verify.h> #ifdef HAVE_SYS_SYSLIMITS_H #include <sys/syslimits.h> @@ -115,6 +116,13 @@ #define ATTRIBUTE_RETURN_CHECK #endif /* __GNUC__ */ +/* + * Use this when passing possibly-NULL strings to printf-a-likes. + */ +#define NULLSTR(s) \ + ((void)verify_true(sizeof *(s) == sizeof (char)), \ + (s) ? (s) : "(null)") + /** * TODO: * diff --git a/src/libvirt.c b/src/libvirt.c --- a/src/libvirt.c +++ b/src/libvirt.c @@ -864,10 +864,10 @@ do_open (const char *name, " port %d\n" " path %s\n", name, - ret->uri->scheme, ret->uri->opaque, - ret->uri->authority, ret->uri->server, - ret->uri->user, ret->uri->port, - ret->uri->path); + NULLSTR(ret->uri->scheme), NULLSTR(ret->uri->opaque), + NULLSTR(ret->uri->authority), NULLSTR(ret->uri->server), + NULLSTR(ret->uri->user), ret->uri->port, + NULLSTR(ret->uri->path)); } else { DEBUG0("no name, allowing driver auto-select"); } @@ -1056,7 +1056,7 @@ virConnectOpenAuth(const char *name, if (virInitialize() < 0) return NULL; - DEBUG("name=%s, auth=%p, flags=%d", name, auth, flags); + DEBUG("name=%s, auth=%p, flags=%d", NULLSTR(name), auth, flags); return do_open (name, auth, flags); }

On Thu, Jan 15, 2009 at 07:19:33AM -0800, john.levon@sun.com wrote:
# HG changeset patch # User john.levon@sun.com # Date 1232032750 28800 # Node ID 0335828806b5b3855c8eeaee31446a7bd0c02974 # Parent e542223a4c52d978d4507de709f50885920a5b44 Avoid passing NULL to printf %s specifier
+1 to this patch. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v

On Thu, Jan 15, 2009 at 07:19:33AM -0800, john.levon@sun.com wrote:
# HG changeset patch # User john.levon@sun.com # Date 1232032750 28800 # Node ID 0335828806b5b3855c8eeaee31446a7bd0c02974 # Parent e542223a4c52d978d4507de709f50885920a5b44 Avoid passing NULL to printf %s specifier
ACK, please push :-) Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Thu, Jan 15, 2009 at 07:19:33AM -0800, john.levon@sun.com wrote:
# HG changeset patch # User john.levon@sun.com # Date 1232032750 28800 # Node ID 0335828806b5b3855c8eeaee31446a7bd0c02974 # Parent e542223a4c52d978d4507de709f50885920a5b44 Avoid passing NULL to printf %s specifier
This is non-portable.
Signed-off-by: John Levon <john.levon@sun.com>
ACK. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (4)
-
Daniel P. Berrange
-
Daniel Veillard
-
john.levon@sun.com
-
Richard W.M. Jones