summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2014-07-20 22:32:39 -0400
committerColin Walters <walters@verbum.org>2014-07-21 07:58:07 -0400
commitcdaa9517afc5cd85da7c92ffa272417771632a07 (patch)
tree4cfd70968f8834ead2eee9eaa1a885b3d9719ff2
parente3928205413592ad9f687746401fe484983ecbe8 (diff)
downloadostree-cdaa9517afc5cd85da7c92ffa272417771632a07.tar.gz
repofile: Avoid segfault if querying child in non-directory
The user might "ostree ls /usr/bin/bash/blah", which previously would segfault. A somewhat related future enhancement here would be for "ostree ls" to follow symbolic links. Reported-by: Dusty Mabe <dustymabe@gmail.com> https://bugzilla.gnome.org/show_bug.cgi?id=733476
-rw-r--r--src/libostree/ostree-repo-file.c7
-rwxr-xr-xtests/test-basic.sh7
2 files changed, 14 insertions, 0 deletions
diff --git a/src/libostree/ostree-repo-file.c b/src/libostree/ostree-repo-file.c
index 454b523b..f3215c62 100644
--- a/src/libostree/ostree-repo-file.c
+++ b/src/libostree/ostree-repo-file.c
@@ -223,6 +223,13 @@ do_resolve_nonroot (OstreeRepoFile *self,
if (!ostree_repo_file_ensure_resolved (self->parent, error))
goto out;
+ if (!self->parent->tree_contents)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY,
+ "Not a directory");
+ goto out;
+ }
+
i = ostree_repo_file_tree_find_child (self->parent, self->name, &is_dir, &container);
if (i < 0)
diff --git a/tests/test-basic.sh b/tests/test-basic.sh
index 19e98b1e..e0783855 100755
--- a/tests/test-basic.sh
+++ b/tests/test-basic.sh
@@ -268,6 +268,13 @@ $OSTREE ls test2
echo "ok ls with no argument"
cd ${test_tmpdir}
+if $OSTREE ls test2 /baz/cow/notadir 2>errmsg; then
+ assert_not_reached
+fi
+assert_file_has_content errmsg "Not a directory"
+echo "ok ls of not a directory"
+
+cd ${test_tmpdir}
$OSTREE show test2
echo "ok show with non-checksum"