bug-hurd
[Top][All Lists]
Advanced

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

Re: [PATCH] Allow /hurd/init to be a symlink


From: Ludovic Courtès
Subject: Re: [PATCH] Allow /hurd/init to be a symlink
Date: Mon, 07 Nov 2011 22:15:43 +0100
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.90 (gnu/linux)

Hi,

Samuel Thibault <samuel.thibault@gnu.org> skribis:

> Ludovic Courtès, le Mon 07 Nov 2011 21:35:06 +0100, a écrit :
>> + lookup_init:
>>    err = dir_lookup (root_pt, initname, O_READ, 0,
>>                  &retry, pathbuf, &startup_pt);
>>    if (err)
>> @@ -232,6 +233,13 @@ diskfs_start_bootstrap ()
>>        free (exec_argv);
>>        assert_perror (err);  /* XXX this won't reboot properly */
>>      }
>> +  else if (retry == FS_RETRY_MAGICAL && pathbuf[0] == '/')
>> +    {
>> +      /* INITNAME is a symlink with an absolute target, so try again.  */
>> +      initname = strdupa (pathbuf);
>> +      goto lookup_init;
>> +    }
>
> It'd be good to use SYMLOOK_MAX to avoid potential infinite recursion
> which would lead to stack overflow.

Yes (though it’s the administrator who set up the symlink, so it could
be argued that it can be trusted to not be infinite.)

How about this updated version?

diff --git a/libdiskfs/boot-start.c b/libdiskfs/boot-start.c
index e73e4d3..15563bd 100644
--- a/libdiskfs/boot-start.c
+++ b/libdiskfs/boot-start.c
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 1993,94,95,96,97,98,99,2000,01,02,10
+   Copyright (C) 1993,94,95,96,97,98,99,2000,01,02,10,11
        Free Software Foundation, Inc.
 
 This file is part of the GNU Hurd.
@@ -104,6 +104,7 @@ diskfs_start_bootstrap ()
   struct protid *rootpi;
   struct peropen *rootpo;
   mach_port_t diskfs_exec;
+  unsigned int init_lookups = 0;
 
   /* Create the port for current and root directory.  */
   err = diskfs_make_peropen (diskfs_root_node, O_READ | O_EXEC, 0,
@@ -222,8 +223,10 @@ diskfs_start_bootstrap ()
       initname = exec_argv + 1;
     }
 
+ lookup_init:
   err = dir_lookup (root_pt, initname, O_READ, 0,
                    &retry, pathbuf, &startup_pt);
+  init_lookups++;
   if (err)
     {
       printf ("\nCannot find startup program `%s': %s\n",
@@ -232,6 +235,15 @@ diskfs_start_bootstrap ()
       free (exec_argv);
       assert_perror (err);     /* XXX this won't reboot properly */
     }
+  else if (retry == FS_RETRY_MAGICAL && pathbuf[0] == '/')
+    {
+      assert (init_lookups < SYMLOOP_MAX);
+
+      /* INITNAME is a symlink with an absolute target, so try again.  */
+      initname = strdupa (pathbuf);
+      goto lookup_init;
+    }
+
   assert (retry == FS_RETRY_NORMAL);
   assert (pathbuf[0] == '\0');
 
Thanks,
Ludo’.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]