diff options
author | Richard Jones <rjones@redhat.com> | 2010-05-19 12:27:00 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2010-05-20 10:30:12 +0100 |
commit | 30c091f49dafab4ca9c8b6640d19fc0450b15971 (patch) | |
tree | c4bba201e9cff32aeb533041bbb8ee3d2b49dd7b /regressions | |
parent | e715451fae0ba738973af98a4e506b6c5564626a (diff) | |
download | libguestfs-30c091f49dafab4ca9c8b6640d19fc0450b15971.tar.gz libguestfs-30c091f49dafab4ca9c8b6640d19fc0450b15971.tar.xz libguestfs-30c091f49dafab4ca9c8b6640d19fc0450b15971.zip |
generator: Check parameters are not NULL (RHBZ#501893).
This adds additional tests to check that several types of parameter
including String are not NULL when passed to the C functions.
Previously this would cause a segfault inside libguestfs. With
this change, you get an error message / exception.
Of the possible pointer parameters, only OptString is now permitted
to be NULL.
This change does not affect the Perl bindings. This is because Perl
XS code was already adding similar checks if you passed undef into
a parameter expecting a string.
Diffstat (limited to 'regressions')
-rw-r--r-- | regressions/Makefile.am | 11 | ||||
-rw-r--r-- | regressions/rhbz501893.c | 50 |
2 files changed, 61 insertions, 0 deletions
diff --git a/regressions/Makefile.am b/regressions/Makefile.am index 7ec9dc83..385de458 100644 --- a/regressions/Makefile.am +++ b/regressions/Makefile.am @@ -24,6 +24,7 @@ include $(top_srcdir)/subdir-rules.mk TESTS = \ + rhbz501893 \ rhbz503169c10.sh \ rhbz503169c13.sh \ rhbz557655.sh \ @@ -58,6 +59,16 @@ TESTS_ENVIRONMENT = \ PERL5LIB=$(top_builddir)/perl/blib/lib:$(top_builddir)/perl/blib/arch \ NOEXEC_CHECK="$(top_builddir)/src/.libs/libguestfs.so $(top_builddir)/daemon/guestfsd" +check_PROGRAMS = \ + rhbz501893 + +rhbz501893_SOURCES = rhbz501893.c +rhbz501893_CFLAGS = \ + -I$(top_srcdir)/src -I$(top_builddir)/src \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) +rhbz501893_LDADD = \ + $(top_builddir)/src/libguestfs.la + EXTRA_DIST = \ $(FAILING_TESTS) \ $(SKIPPED_TESTS) \ diff --git a/regressions/rhbz501893.c b/regressions/rhbz501893.c new file mode 100644 index 00000000..54c052d5 --- /dev/null +++ b/regressions/rhbz501893.c @@ -0,0 +1,50 @@ +/* Regression test for RHBZ#501893. + * Test that String parameters are checked for != NULL. + * Copyright (C) 2009-2010 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> + +#include "guestfs.h" + +int +main (int argc, char *argv[]) +{ + guestfs_h *g = guestfs_create (); + + /* Call some non-daemon functions that have a String parameter, but + * setting that parameter to NULL. Previously this would cause a + * segfault inside libguestfs. After this bug was fixed, this + * turned into an error message. + */ + + assert (guestfs_add_drive (g, NULL) == -1); + assert (guestfs_config (g, NULL, NULL) == -1); + + /* These can be safely set to NULL, should be no error. */ + + assert (guestfs_set_path (g, NULL) == 0); + assert (guestfs_set_append (g, NULL) == 0); + assert (guestfs_set_qemu (g, NULL) == 0); + + guestfs_close (g); + exit (0); +} |