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;