If opening the backing store fails during a metadata-only open,
check_dev() ignores the error and leaves dev->store NULL.
create_partitions() then passes it to ped_device_new_from_store(),
triggering Parted's "source != NULL" assertion.

Ensure the backing store is open before probing partitions and
propagate any error.

To reproduce (with /tmp/no-such-image absent):
  touch /tmp/storeio-node
  settrans -ac /tmp/storeio-node /hurd/storeio -r -T file /tmp/no-such-image
  stat /tmp/storeio-node/1

Before this patch, storeio aborts and stat reports "Computer bought
the farm". With the patch, stat reports "No such file or directory"
and storeio remains running.

---
 storeio/part.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/storeio/part.c b/storeio/part.c
index 47d37df7..142427db 100644
--- a/storeio/part.c
+++ b/storeio/part.c
@@ -17,6 +17,7 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. */

+#include <fcntl.h>
 #include <parted/parted.h>
 #include <hurd/store.h>

@@ -91,6 +92,11 @@ create_partitions (void)
 {
   debug ("create_partitions:\n");
   struct node *dir = netfs_root_node;
+  /* A lookup can reach us before the root has been opened for I/O.  */
+  error_t err = check_dev (dir, NULL, O_READ);
+  if (err)
+    return err;
+
   size_t last_partition_num =
     (size_t) set_last_partition_num (dir->nn->dev->store);
   if (last_partition_num == 0)
@@ -100,7 +106,6 @@ create_partitions (void)
       return ENOTDIR;
     }

-  error_t err;
   dir->nn->entries_num = last_partition_num;
   dir->nn->entries = malloc (last_partition_num * sizeof (struct node *));
   if (!dir->nn->entries)

Reply via email to