summaryrefslogtreecommitdiffstats
path: root/src/inspect_fs_unix.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-05-24 15:40:36 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-06-01 19:25:49 +0100
commitf697f9ea97ee3e3aa73b3d4d79643b892afb0603 (patch)
tree9db2199431f0e54be152172516833a7cd144393e /src/inspect_fs_unix.c
parentcdbb3008ccfd21003df635c3d522051c02f19e15 (diff)
downloadlibguestfs-f697f9ea97ee3e3aa73b3d4d79643b892afb0603.tar.gz
libguestfs-f697f9ea97ee3e3aa73b3d4d79643b892afb0603.tar.xz
libguestfs-f697f9ea97ee3e3aa73b3d4d79643b892afb0603.zip
inspection: Don't fail if /etc/HOSTNAME or /etc/hostname are empty files (RHBZ#823821).
Change guestfs___first_line_of_file so that if the file is empty this returns an empty string instead of an error. This is consistent with the behaviour of this function in the case where the file starts with a \n character, where it would previously have returned an empty string. Change all callers so that they handle this case. Then change the hostname parsing code so that it doesn't give up when /etc/HOSTNAME is empty, but falls through to the next alternative, and similarly for /etc/hostname. Thanks Todd Mummert for finding and diagnosing this bug. (cherry picked from commit f00066d22b11bf40d0272f68565a2a27fea15627)
Diffstat (limited to 'src/inspect_fs_unix.c')
-rw-r--r--src/inspect_fs_unix.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/inspect_fs_unix.c b/src/inspect_fs_unix.c
index 2caf4002..06936c23 100644
--- a/src/inspect_fs_unix.c
+++ b/src/inspect_fs_unix.c
@@ -181,6 +181,12 @@ parse_release_file (guestfs_h *g, struct inspect_fs *fs,
fs->product_name = guestfs___first_line_of_file (g, release_filename);
if (fs->product_name == NULL)
return -1;
+ if (STREQ (fs->product_name, "")) {
+ free (fs->product_name);
+ fs->product_name = NULL;
+ error (g, _("release file %s is empty or malformed"), release_filename);
+ return -1;
+ }
return 0;
}
@@ -659,13 +665,23 @@ check_hostname_unix (guestfs_h *g, struct inspect_fs *fs)
fs->hostname = guestfs___first_line_of_file (g, "/etc/HOSTNAME");
if (fs->hostname == NULL)
return -1;
+ if (STREQ (fs->hostname, "")) {
+ free (fs->hostname);
+ fs->hostname = NULL;
+ }
}
- else if (guestfs_is_file (g, "/etc/hostname")) {
+
+ if (!fs->hostname && guestfs_is_file (g, "/etc/hostname")) {
fs->hostname = guestfs___first_line_of_file (g, "/etc/hostname");
if (fs->hostname == NULL)
return -1;
+ if (STREQ (fs->hostname, "")) {
+ free (fs->hostname);
+ fs->hostname = NULL;
+ }
}
- else if (guestfs_is_file (g, "/etc/sysconfig/network")) {
+
+ if (!fs->hostname && guestfs_is_file (g, "/etc/sysconfig/network")) {
const char *configfiles[] = { "/etc/sysconfig/network", NULL };
if (inspect_with_augeas (g, fs, configfiles,
check_hostname_redhat) == -1)