All of lore.kernel.org
 help / color / mirror / Atom feed
From: Darren Kenny <darren.kenny@oracle.com>
To: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>,
	The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: [PATCH 2/2] util: confirm directory creation in grub_install_mkdir_p
Date: Tue, 09 Aug 2022 16:34:19 +0100	[thread overview]
Message-ID: <m2czd9e8hw.fsf@oracle.com> (raw)
In-Reply-To: <CAEaD8JNDSfc78ptd=DhfBNO=sJ-0Eyu5zSncT_+mGUmZoOYGjQ@mail.gmail.com>

Hi Vladimir,

I admit, that I did not previously.

I just tried it out where one of the components in a deeper path was a
symlink, and it works as I would expect. It will see it as a
directory in grub_util_is_directory() using stat(), since that is
looking at what is pointed to, in comparison to lstat(), which only
looks at the symlink itself.

Thanks,

Darren.

On Tuesday, 2022-08-09 at 16:04:32 +02, Vladimir Serbinenko wrote:
> Did you test the case when some of components exist and are symlinks? E.g.
> /temp being a symlinkto /var/tmp
>
> Le mar. 9 août 2022, 15:30, Darren Kenny <darren.kenny@oracle.com> a écrit :
>
>> Because grub_util_mkdir() is implemented to not return a value on any
>> platform, grub_instal_mkdir_p can test for success by confirming that
>> the directory requested exists after attempting to create it, otherwise
>> it should fail with an error and exit.
>>
>> While fixing this, a flaw in the logic was shown, where the first match
>> of the path separator, which almost always was the first character in
>> the path (e.g. /boot/grub2) would result in creating a directory with an
>> empty name (i.e. ""). To avoid that, it should skip the handling of the
>> path separator where p is pointing to the first character.
>>
>> Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
>> ---
>>  util/grub-install-common.c | 7 ++++++-
>>  1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/util/grub-install-common.c b/util/grub-install-common.c
>> index 347558bf5412..035293c2357e 100644
>> --- a/util/grub-install-common.c
>> +++ b/util/grub-install-common.c
>> @@ -173,15 +173,20 @@ grub_install_mkdir_p (const char *dst)
>>    char *p;
>>    for (p = t; *p; p++)
>>      {
>> -      if (is_path_separator (*p))
>> +      if (is_path_separator (*p) && p != t)
>>         {
>>           char s = *p;
>>           *p = '\0';
>>           grub_util_mkdir (t);
>> +         if (!grub_util_is_directory(t))
>> +           grub_util_error (_("failed to make directory: '%s'"), t);
>> +
>>           *p = s;
>>         }
>>      }
>>    grub_util_mkdir (t);
>> +  if (!grub_util_is_directory(t))
>> +    grub_util_error (_("failed to make directory: '%s'"), t);
>>    free (t);
>>  }
>>
>> --
>> 2.31.1
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel


  reply	other threads:[~2022-08-09 15:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09 13:29 [PATCH 0/2] util: Resolve issues with use of grub_util_mkdir Darren Kenny
2022-08-09 13:29 ` [PATCH 1/2] util: Ignore return value for grub_util_mkdir() on all platforms Darren Kenny
2022-08-09 13:29 ` [PATCH 2/2] util: confirm directory creation in grub_install_mkdir_p Darren Kenny
2022-08-09 14:04   ` Vladimir 'phcoder' Serbinenko
2022-08-09 15:34     ` Darren Kenny [this message]
2022-08-19 17:09 ` [PATCH 0/2] util: Resolve issues with use of grub_util_mkdir Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2czd9e8hw.fsf@oracle.com \
    --to=darren.kenny@oracle.com \
    --cc=grub-devel@gnu.org \
    --cc=phcoder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.