From patchwork Mon Jul 2 00:41:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 937630 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41JpNp4VQmz9s4Z for ; Mon, 2 Jul 2018 10:42:01 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B8ABDC21D74; Mon, 2 Jul 2018 00:41:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_SORBS_WEB autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A9DD0C21C57; Mon, 2 Jul 2018 00:41:51 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 36B13C21C27; Mon, 2 Jul 2018 00:41:50 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lists.denx.de (Postfix) with ESMTPS id D83E2C21BE5 for ; Mon, 2 Jul 2018 00:41:49 +0000 (UTC) Received: from localhost.localdomain ([89.204.153.253]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LbR3e-1fyeLT1cCo-00kvoc; Mon, 02 Jul 2018 02:41:45 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Mon, 2 Jul 2018 02:41:23 +0200 Message-Id: <20180702004124.13042-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180702004124.13042-1-xypron.glpk@gmx.de> References: <20180702004124.13042-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K1:BKUADTse5klVoQdCvKoCY8aj6+SC/9AIJ4/JTR8vVeA4B7ZmBxx mUhHYqd81OMvXGu/1x/DWAGrzwU1jTw4bJM8pMTKrQOjHhnOT2UK/TGlLM1mL86SWdsClwT Q4TLfR8gHhZREvwU46GqBXXlxtz/iHA0ItaumB1Po991wTdL9Dd+TSvLpLxBAljZh6Jww6f iXllPtUgymHt2xo5k2cMw== X-UI-Out-Filterresults: notjunk:1; V01:K0:k5gz+XE7J1M=:HIGAZeCyT9klK3oPAQDoI7 2BANGQ7we8k/j+zYiG44+xZLsh9dGPF+MC+jzyT8IE8rgDDnE1xShjJp62u8Jo4oxZiS5aMq5 0z3fiPFZyB/44bWvpti4ILyQA9Qp3jxhi501Zu/iu8E5uv6Xq6wDTUlSTJ1sEBoboPg3iMSqw qXEFpQE31iUcbzNKyrvG41+WTXcxNgXisTy0LLpVjMHtJJu2frcjp8F2rEl7TUad9NW0gRIx+ lUtAxf4C7mNySH7Jy9SoQQb4X5Jplo0USfzd03bVFLXa733eZ7dKnHqRCPHLuFxvueKtvVqOa HhW7ujIttGsqIBu1DeYaMZ03150yfo6lCb2awHMK31xSK/sy/zCnVBosiBG18AzERjH+upM25 LezU1HmQMJVQxKzXkmIj29J1LvdR7iMDFAUfsiFApUTzYW2Cv5XxvgjEVZcmYrNntf9RCqlDy eU5VKp36ydQcwQt2NYadP3wwMclwYWxRocJYr9LbTnFy8Er+KO9R6f9RemXSxl315n5SUcDuM cbPb6TrDshUg5/v9LHfdo+3AhEZrmTrhmRVSFTk1uUAx+zfb1v9W/GJOBZBS8uZrOUhC6TQNK /1YHtO69Fvup8W9CAiF5ZO2qZ+fJBBegKGiTVrx2rtyHqw+jk0LZh2Dht0QZFD7SeqcOSgY7u xcAWBvWdDJfBBCC/YK2poX7fWhYcmmf9sGLq/Q6AZWSuomQDJGUNjgw53dzO968dGrxIHySIk +yxCSPricplkGOk8AgrQx3/m/OXGfQoDLGFkPsXt1UplmjBu8qXRML01QK8= Cc: Heinrich Schuchardt , u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 1/2] fs: fat: cannot write to subdirectories X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- fs/fat/fat_write.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 5ca8fcda73..c5aee519b7 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,18 @@ 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 ISDIRDELIM(*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; From patchwork Mon Jul 2 00:41:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 937632 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41JpQS62ywz9s4r for ; Mon, 2 Jul 2018 10:43:28 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 817C9C21DEC; Mon, 2 Jul 2018 00:42:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_SORBS_WEB autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 45AD6C21DFF; Mon, 2 Jul 2018 00:41:54 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EDCAAC21C27; Mon, 2 Jul 2018 00:41:51 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lists.denx.de (Postfix) with ESMTPS id 66BC8C21BE5 for ; Mon, 2 Jul 2018 00:41:51 +0000 (UTC) Received: from localhost.localdomain ([89.204.153.253]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0Mecqq-1fki3e0VzM-00OIa4; Mon, 02 Jul 2018 02:41:46 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Mon, 2 Jul 2018 02:41:24 +0200 Message-Id: <20180702004124.13042-3-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180702004124.13042-1-xypron.glpk@gmx.de> References: <20180702004124.13042-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K1:7zijal51P7DFpW7EeBfADvGhpoml/rSA9bezrKzedkqiG9lPzkC TlVbDlzfWmwErkEtduSNCqla2Wk8BAia5pPZePMz/5oOSbSyg5Wt80rVkU95qEx0gazb0hT sxchlp4zqYiQzpSjy0/IiDc1aCSo1quL1FjhDbvsI5ZKFI7KkmA4Zbm63jahgjlD+8R+RcQ nrx1XFIhPIpcyeaKI8Bfw== X-UI-Out-Filterresults: notjunk:1; V01:K0:stYFu2dmxa4=:tuW+mXOx5l8v0OT9oNsT6H hNe7Bd6oaOlq33Hwl0ygxKZlZ4SyJ9q7npHUQ0TOw8agyRevnW2/s6F+Yc1UcN1DJAaox9wJ0 1frSRdYLf3VZ0l4ropKxtifpfsYARHEdWvfqI+BPUEqqZkvWdwtgV8e47FRwdNNFIDf88EJBD WHWQLSKhuw22hJYuNbzig7zQphR7tNva0kpdGPB1e813HsbZtcCrszBplvPu6wQqRv28DRkud og7KobOdveD6tyC8Dk8xr34OaKaSWWOeJM80gBeHE+Yh9y2Tp3wFE4FgFeF5ITFAcbXKLt2cV 2cT57gMWcsQ6VzegjahEkgZ6FLrmUtEf7HaKoWoY6+4aJjWEoYz9tqbS2AsBt2U/kQ13P66Gc WQgCwuDEpd0UoCKt7PX09vjWl1tvL3eFZC0NZ6ly+3bq6oI+FWdPmyncnOCMohlFPTBr/JneV z8h9mNytON9rDEBJ0ZuOpFU72QHhvabUneEgcjn+blgQCDXyG/zwjrjTIqtE8d+NIykbPJCCi Ys1kLgcUQy3sQ2meu11ipEGZ5HVY3f0uZsIRK/ixwOCGgocxZvGqgSkjnzqzPc1VGuerqTAbA qVxc6Q7tJ4UM3FDJ0dtN4OOssE7o22fqqCib15fuf8GoXvqXI3uROIs6ogMVRm4OgCudzOKph dUyGPqB4Bq6rCEDTancCtq9xjQJVKrL2bZp4PXSTGtKbxSfPI7R7VGKPpF5B46K6nVd43lSnb KpNA5rz8NV9aD/+wteild58iC9Zl1Nc3F0wwHtBAlRRH7atskLuc5vx/VtA= Cc: Heinrich Schuchardt , u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 2/2] efi_selftest: test writing to file X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Provide a unit test for writing to a FAT file system. Add some additional comments in block device unit test. Signed-off-by: Heinrich Schuchardt --- lib/efi_selftest/efi_selftest_block_device.c | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/lib/efi_selftest/efi_selftest_block_device.c b/lib/efi_selftest/efi_selftest_block_device.c index 4af8bd8cb2..b82e405030 100644 --- a/lib/efi_selftest/efi_selftest_block_device.c +++ b/lib/efi_selftest/efi_selftest_block_device.c @@ -309,11 +309,14 @@ static int execute(void) efi_uintn_t buf_size; char buf[16] __aligned(ARCH_DMA_MINALIGN); + /* Connect controller to virtual disk */ ret = boottime->connect_controller(disk_handle, NULL, NULL, 1); if (ret != EFI_SUCCESS) { efi_st_error("Failed to connect controller\n"); return EFI_ST_FAILURE; } + + /* Get the handle for the partition */ ret = boottime->locate_handle_buffer( BY_PROTOCOL, &guid_device_path, NULL, &no_handles, &handles); @@ -347,6 +350,8 @@ static int execute(void) efi_st_error("Partition handle not found\n"); return EFI_ST_FAILURE; } + + /* Open the simple file system protocol */ ret = boottime->open_protocol(handle_partition, &guid_simple_file_system_protocol, (void **)&file_system, NULL, NULL, @@ -355,6 +360,8 @@ static int execute(void) efi_st_error("Failed to open simple file system protocol\n"); return EFI_ST_FAILURE; } + + /* Open volume */ ret = file_system->open_volume(file_system, &root); if (ret != EFI_SUCCESS) { efi_st_error("Failed to open volume\n"); @@ -377,6 +384,8 @@ static int execute(void) "Wrong volume label '%ps', expected 'U-BOOT TEST'\n", system_info.info.volume_label); } + + /* Read file */ ret = root->open(root, &file, (s16 *)L"hello.txt", EFI_FILE_MODE_READ, 0); if (ret != EFI_SUCCESS) { @@ -389,6 +398,11 @@ static int execute(void) efi_st_error("Failed to read file\n"); return EFI_ST_FAILURE; } + if (buf_size != 13) { + efi_st_error("Wrong number of bytes read: %u\n", + (unsigned int)buf_size); + return EFI_ST_FAILURE; + } if (efi_st_memcmp(buf, "Hello world!", 12)) { efi_st_error("Unexpected file content\n"); return EFI_ST_FAILURE; @@ -398,6 +412,62 @@ static int execute(void) efi_st_error("Failed to close file\n"); return EFI_ST_FAILURE; } + +#ifdef CONFIG_FAT_WRITE + /* Write file */ + ret = root->open(root, &file, (s16 *)L"u-boot.txt", + EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open file\n"); + return EFI_ST_FAILURE; + } + buf_size = 7; + boottime->set_mem(buf, sizeof(buf), 0); + boottime->copy_mem(buf, "U-Boot", buf_size); + ret = file->write(file, &buf_size, buf); + if (ret != EFI_SUCCESS || buf_size != 7) { + efi_st_error("Failed to write file\n"); + return EFI_ST_FAILURE; + } + ret = file->close(file); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to close file\n"); + return EFI_ST_FAILURE; + } + + /* Verify file */ + boottime->set_mem(buf, sizeof(buf), 0); + ret = root->open(root, &file, (s16 *)L"u-boot.txt", EFI_FILE_MODE_READ, + 0); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open file\n"); + return EFI_ST_FAILURE; + } + buf_size = sizeof(buf) - 1; + ret = file->read(file, &buf_size, buf); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to read file\n"); + return EFI_ST_FAILURE; + } + if (buf_size != 7) { + efi_st_error("Wrong number of bytes read: %u\n", + (unsigned int)buf_size); + return EFI_ST_FAILURE; + } + if (efi_st_memcmp(buf, "U-Boot", 7)) { + efi_st_error("Unexpected file content %s\n", buf); + return EFI_ST_FAILURE; + } + ret = file->close(file); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to close file\n"); + return EFI_ST_FAILURE; + } +#else + efi_st_todo("CONFIG_FAT_WRITE is not set\n"); +#endif /* CONFIG_FAT_WRITE */ + + /* Close volume */ ret = root->close(root); if (ret != EFI_SUCCESS) { efi_st_error("Failed to close volume\n");