From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC 1/3] fs: fat: cannot write to subdirectories
Date: Mon, 28 May 2018 09:30:26 +0200 [thread overview]
Message-ID: <20180528093026.3f75a701@jawa> (raw)
In-Reply-To: <20180526083447.2917-2-xypron.glpk@gmx.de>
On Sat, 26 May 2018 10:34:45 +0200
Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> fs_fat_write() is not able to write to subdirectories.
>
> Currently if a filepath with a leading slash is passed, the slash is
> treated as part of the filename to be created in the root directory.
>
> Strip leading (back-)slashes.
>
> Check that the remaining filename does not contain any illegal
> characters (<>:"/\|?*). This way we will throw an error when trying
> to write to a subdirectory.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> fs/fat/fat_write.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
> index 5ca8fcda73c..f32745febb4 100644
> --- a/fs/fat/fat_write.c
> +++ b/fs/fat/fat_write.c
> @@ -908,9 +908,11 @@ static int do_fat_write(const char *filename,
> void *buffer, loff_t size, volume_info volinfo;
> fsdata datablock;
> fsdata *mydata = &datablock;
> - int cursect;
> + int cursect, i;
> int ret = -1, name_len;
> char l_filename[VFAT_MAXLEN_BYTES];
> + char bad[2] = " ";
> + const char illegal[] = "<>:\"/\\|?*";
>
> *actwrite = size;
> dir_curclust = 0;
> @@ -970,6 +972,20 @@ static int do_fat_write(const char *filename,
> void *buffer, loff_t size, }
> dentptr = (dir_entry *) do_fat_read_at_block;
>
> + /* Strip leading (back-)slashes */
> + while (*filename == '/')
> + ++filename;
> + while (*filename == '\\')
> + ++filename;
> + /* Check that the filename is valid */
> + for (i = 0; i < strlen(illegal); ++i) {
> + *bad = illegal[i];
> + if (strstr(filename, bad)) {
> + printf("FAT: illegal filename (%s)\n",
> filename);
> + return -1;
> + }
> + }
> +
> name_len = strlen(filename);
> if (name_len >= VFAT_MAXLEN_BYTES)
> name_len = VFAT_MAXLEN_BYTES - 1;
Reviewed-by: Lukasz Majewski <lukma@denx.de>
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180528/81898d40/attachment.sig>
next prev parent reply other threads:[~2018-05-28 7:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-26 8:34 [U-Boot] [RFC 0/3] efi_loader: allow writing to FAT Heinrich Schuchardt
2018-05-26 8:34 ` [U-Boot] [RFC 1/3] fs: fat: cannot write to subdirectories Heinrich Schuchardt
2018-05-28 7:30 ` Lukasz Majewski [this message]
2018-05-26 8:34 ` [U-Boot] [RFC 2/3] efi_selftest: imply FAT, FAT_WRITE Heinrich Schuchardt
2018-05-26 8:34 ` [U-Boot] [RFC 3/3] efi_selftest: test writing to file Heinrich Schuchardt
2018-06-01 7:13 ` AKASHI, Takahiro
2018-06-01 7:38 ` Heinrich Schuchardt
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=20180528093026.3f75a701@jawa \
--to=lukma@denx.de \
--cc=u-boot@lists.denx.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox