[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 2/2] actions: turn some params into FilenameList (RHBZ#1174551).



Use FilenameList as type for lists of file names, as used in some
listing-alike APIs.  This way we can ensure anything different than just
file names in those lists is rejected outright.

As a consequence, test-big-dirs.pl does not need to prepend the
directory name anymore before calling listing-alike APIs: previously
they didn't fail, but the returned lists contained only invalid
elements (and only their size was checked).

Furthermore, add a new regression test for it.
---
 generator/actions.ml             | 14 +++++-----
 tests/bigdirs/test-big-dirs.pl   |  1 -
 tests/regressions/Makefile.am    |  2 ++
 tests/regressions/rhbz1174551.sh | 58 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 67 insertions(+), 8 deletions(-)
 create mode 100755 tests/regressions/rhbz1174551.sh

diff --git a/generator/actions.ml b/generator/actions.ml
index 10acb7c..62176ab 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -2655,7 +2655,7 @@ See also C<guestfs_write>." };
 
   { defaults with
     name = "lstatlist"; added = (1, 0, 77);
-    style = RStructList ("statbufs", "stat"), [Pathname "path"; StringList "names"], [];
+    style = RStructList ("statbufs", "stat"), [Pathname "path"; FilenameList "names"], [];
     deprecated_by = Some "lstatnslist";
     shortdesc = "lstat on multiple files";
     longdesc = "\
@@ -2675,7 +2675,7 @@ for getting extended attributes." };
 
   { defaults with
     name = "lstatnslist"; added = (1, 27, 53);
-    style = RStructList ("statbufs", "statns"), [Pathname "path"; StringList "names"], [];
+    style = RStructList ("statbufs", "statns"), [Pathname "path"; FilenameList "names"], [];
     shortdesc = "lstat on multiple files";
     longdesc = "\
 This call allows you to perform the C<guestfs_lstatns> operation
@@ -2694,7 +2694,7 @@ for getting extended attributes." };
 
   { defaults with
     name = "lxattrlist"; added = (1, 0, 77);
-    style = RStructList ("xattrs", "xattr"), [Pathname "path"; StringList "names"], [];
+    style = RStructList ("xattrs", "xattr"), [Pathname "path"; FilenameList "names"], [];
     optional = Some "linuxxattrs";
     shortdesc = "lgetxattr on multiple files";
     longdesc = "\
@@ -2719,7 +2719,7 @@ for getting standard stats." };
 
   { defaults with
     name = "readlinklist"; added = (1, 0, 77);
-    style = RStringList "links", [Pathname "path"; StringList "names"], [];
+    style = RStringList "links", [Pathname "path"; FilenameList "names"], [];
     shortdesc = "readlink on multiple files";
     longdesc = "\
 This call allows you to do a C<readlink> operation
@@ -7703,7 +7703,7 @@ yourself (Augeas support makes this relatively easy)." };
 
   { defaults with
     name = "internal_lxattrlist"; added = (1, 19, 32);
-    style = RStructList ("xattrs", "xattr"), [Pathname "path"; StringList "names"], [];
+    style = RStructList ("xattrs", "xattr"), [Pathname "path"; FilenameList "names"], [];
     proc_nr = Some 205;
     visibility = VInternal;
     optional = Some "linuxxattrs";
@@ -7733,7 +7733,7 @@ into smaller groups of names." };
 
   { defaults with
     name = "internal_readlinklist"; added = (1, 19, 32);
-    style = RStringList "links", [Pathname "path"; StringList "names"], [];
+    style = RStringList "links", [Pathname "path"; FilenameList "names"], [];
     proc_nr = Some 206;
     visibility = VInternal;
     shortdesc = "readlink on multiple files";
@@ -12220,7 +12220,7 @@ This is the same as the L<lstat(2)> system call." };
 
   { defaults with
     name = "internal_lstatnslist"; added = (1, 27, 53);
-    style = RStructList ("statbufs", "statns"), [Pathname "path"; StringList "names"], [];
+    style = RStructList ("statbufs", "statns"), [Pathname "path"; FilenameList "names"], [];
     proc_nr = Some 423;
     visibility = VInternal;
     shortdesc = "lstat on multiple files";
diff --git a/tests/bigdirs/test-big-dirs.pl b/tests/bigdirs/test-big-dirs.pl
index 40038b7..5bcc71c 100755
--- a/tests/bigdirs/test-big-dirs.pl
+++ b/tests/bigdirs/test-big-dirs.pl
@@ -63,7 +63,6 @@ for (my $i = 0; $i < $nr_files; ++$i) {
 # Check that lstatlist, lxattrlist and readlinklist return the
 # expected number of entries.
 my @a;
- filenames = map { "/dir/$_" } @filenames;
 
 @a = $g->lstatlist ("/dir", \ filenames);
 die unless @a == $nr_files;
diff --git a/tests/regressions/Makefile.am b/tests/regressions/Makefile.am
index 026987b..18a4f37 100644
--- a/tests/regressions/Makefile.am
+++ b/tests/regressions/Makefile.am
@@ -43,6 +43,7 @@ EXTRA_DIST = \
 	rhbz1044014.xml \
 	rhbz1054761.sh \
 	rhbz1091803.sh \
+	rhbz1174551.sh \
 	rhbz1175196.sh \
 	rhbz1232192.sh \
 	rhbz1232192.xml \
@@ -71,6 +72,7 @@ TESTS = \
 	rhbz1055452 \
 	rhbz1091803.sh \
 	rhbz1011907-1165785.sh \
+	rhbz1174551.sh \
 	rhbz1175196.sh \
 	rhbz1232192.sh \
 	test-big-heap \
diff --git a/tests/regressions/rhbz1174551.sh b/tests/regressions/rhbz1174551.sh
new file mode 100755
index 0000000..fdc595c
--- /dev/null
+++ b/tests/regressions/rhbz1174551.sh
@@ -0,0 +1,58 @@
+#!/bin/bash -
+# libguestfs
+# Copyright (C) 2015 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Regression test for:
+# https://bugzilla.redhat.com/show_bug.cgi?id=1174551
+# check that list-alike APIs accept only relative paths and reject
+# absolute ones
+
+set -e
+export LANG=C
+
+if [ -n "$SKIP_TEST_RHBZ1174551_SH" ]; then
+    echo "$0: test skipped because environment variable is set."
+    exit 77
+fi
+
+if [ ! -s ../guests/fedora.img ]; then
+    echo "$0: test skipped because there is no fedora.img"
+    exit 77
+fi
+
+rm -f test.error
+
+$VG guestfish --ro -a ../guests/fedora.img -i <<EOF 2>test.error
+# valid invocations
+lstatlist /etc "fedora-release sysconfig"
+lstatnslist /etc "fedora-release sysconfig"
+readlinklist /bin "test5"
+
+# invalid invocations
+-lstatlist / "/bin"
+-lstatnslist / "/bin"
+-lstatlist /etc "../bin sysconfig/network"
+-readlinklist /etc "/bin/test5"
+EOF
+
+# check the number of errors in the log
+if [ $(cat test.error | wc -l) -ne 4 ]; then
+    echo "$0: "
+    exit 1
+fi
+
+rm test.error
-- 
2.1.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]