From patchwork Wed Apr 12 20:29:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Hall X-Patchwork-Id: 750157 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3w3FsZ42tMz9sNH for ; Thu, 13 Apr 2017 06:30:10 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hGlZXK+M"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id 53ED5C21C4A; Wed, 12 Apr 2017 20:30:07 +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.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id E1480C21C26; Wed, 12 Apr 2017 20:30:04 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A55E2C21C39; Wed, 12 Apr 2017 20:29:55 +0000 (UTC) Received: from mail-io0-f195.google.com (mail-io0-f195.google.com [209.85.223.195]) by lists.denx.de (Postfix) with ESMTPS id 40D53C21C70 for ; Wed, 12 Apr 2017 20:29:55 +0000 (UTC) Received: by mail-io0-f195.google.com with SMTP id d203so6819090iof.2 for ; Wed, 12 Apr 2017 13:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=17H0db5pIL5Vi7Et+kLy1/eYk+mUFvHJWvCVZfs4S64=; b=hGlZXK+M0lesVUrKaHjjhqLtICz6jW0fa7pSosgBCMYIN5ca/90NU20K/zRkh99YFd viN4CYqtNDcRBk7W2w5mcslw/Kn+WUGECpJ3B5RYOQTQwcPgImSVRwMXE/z2cF9Buh/z 8L5DQBSZf5LJVuTS3ylIc0ddrpkGY9GupM/STMjG/QsUDZx+wrCqW6KosTXMjxuDNDk5 O47Kh6IOBkfQ+i2iOyWuSedpHdiU+XVQowKmYvtHJMPiwopPCrR/gDpko9AqEwB93uYL UKHfNL5m9ZVfpRUdrYERUbZhNlxL+3efHncYdb5p+RiKMMq68kwQq+1W+46AqboE4hT9 f8IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=17H0db5pIL5Vi7Et+kLy1/eYk+mUFvHJWvCVZfs4S64=; b=AQ3RUnFB9VMpFyxphUulgUqhyNLMP0bftR/eG8LKRGwBCBwp2p6/s1yzG5GsNbi0O4 jzHiS1Wa+H9CjFGIfAbpmtMVrPKFX9ZDKavvBDzq2gTN3sV3uKnOi290BPZIcVJK7m8D Z3tuagxgQPW6GLlnyEUuU/h94xsyPfrMN10/Xai5Ft3RXHfc/6DzyyUgIaXc8TNGh/i+ 7rPgZhCJEOG1wdrQa9ts8Z9G0lyF8ef0Vs3qrxSXMKoS7fWsZj/UQsgigpjcIXMrLMb0 EFrC+nOwL6+r8Ktk8NZ0AOepReFRIxu7YfA3b90GoQ1Mcvls6sVaJinvWQhiNjFvLD4D 8mkQ== X-Gm-Message-State: AN3rC/5jyZE/jl7/s6UrA1EIYSSj218d42bWqkpH6bD2tltr0Nj/Tz0n r9ZsfVcDKWWxlg== X-Received: by 10.107.174.228 with SMTP id n97mr133862ioo.166.1492028994115; Wed, 12 Apr 2017 13:29:54 -0700 (PDT) Received: from metric.localdomain ([2605:a000:1707:199:6245:cbff:fe9a:41a]) by smtp.gmail.com with ESMTPSA id s97sm9933527ioi.50.2017.04.12.13.29.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Apr 2017 13:29:53 -0700 (PDT) From: Tyler Hall To: u-boot@lists.denx.de Date: Wed, 12 Apr 2017 16:29:17 -0400 Message-Id: <20170412202917.22045-4-tylerwhall@gmail.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170412202917.22045-1-tylerwhall@gmail.com> References: <20170412202917.22045-1-tylerwhall@gmail.com> Cc: Tyler Hall Subject: [U-Boot] [PATCH v2 3/3] cramfs: basic symlink support 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" Handle symlinks to files in the current directory. Other cases could be handled with additional code, but this is a start. Add explicit errors for absolute paths and links found in the middle of a path (directories). Other cases like '..' or '.' will result with the file not being found as when those path components are explicitly provided. Add a helper to decompress a null-terminated link name which is shared with cramfs_list_inode. Signed-off-by: Tyler Hall --- fs/cramfs/cramfs.c | 62 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/fs/cramfs/cramfs.c b/fs/cramfs/cramfs.c index ca8bc5e12b..228f599d44 100644 --- a/fs/cramfs/cramfs.c +++ b/fs/cramfs/cramfs.c @@ -49,6 +49,9 @@ extern flash_info_t flash_info[]; #define PART_OFFSET(x) ((ulong)x->offset) #endif +static int cramfs_uncompress (unsigned long begin, unsigned long offset, + unsigned long loadoffset); + static int cramfs_read_super (struct part_info *info) { unsigned long root_offset; @@ -94,6 +97,22 @@ static int cramfs_read_super (struct part_info *info) return 0; } +/* Unpack to an allocated buffer, trusting in the inode's size field. */ +static char *cramfs_uncompress_link (unsigned long begin, unsigned long offset) +{ + struct cramfs_inode *inode = (struct cramfs_inode *)(begin + offset); + unsigned long size = CRAMFS_24 (inode->size); + char *link = malloc (size + 1); + + if (!link || cramfs_uncompress (begin, offset, (unsigned long)link) != size) { + free (link); + link = NULL; + } else { + link[size] = '\0'; + } + return link; +} + static unsigned long cramfs_resolve (unsigned long begin, unsigned long offset, unsigned long size, int raw, char *filename) @@ -143,6 +162,33 @@ static unsigned long cramfs_resolve (unsigned long begin, unsigned long offset, p); } else if (S_ISREG (CRAMFS_16 (inode->mode))) { return offset + inodeoffset; + } else if (S_ISLNK (CRAMFS_16 (inode->mode))) { + unsigned long ret; + char *link; + if (p && strlen(p)) { + printf ("unsupported symlink to \ + non-terminal path\n"); + return 0; + } + link = cramfs_uncompress_link (begin, + offset + inodeoffset); + if (!link) { + printf ("%*.*s: Error reading link\n", + namelen, namelen, name); + return 0; + } else if (link[0] == '/') { + printf ("unsupported symlink to \ + absolute path\n"); + free (link); + return 0; + } + ret = cramfs_resolve (begin, + offset, + size, + raw, + strtok(link, "/")); + free (link); + return ret; } else { printf ("%*.*s: unsupported file type (%x)\n", namelen, namelen, name, @@ -235,20 +281,12 @@ static int cramfs_list_inode (struct part_info *info, unsigned long offset) CRAMFS_24 (inode->size), namelen, namelen, name); if ((CRAMFS_16 (inode->mode) & S_IFMT) == S_IFLNK) { - /* symbolic link. - * Unpack the link target, trusting in the inode's size field. - */ - unsigned long size = CRAMFS_24 (inode->size); - char *link = malloc (size); - - if (link != NULL && cramfs_uncompress (PART_OFFSET(info), offset, - (unsigned long) link) - == size) - printf (" -> %*.*s\n", (int) size, (int) size, link); + char *link = cramfs_uncompress_link (PART_OFFSET(info), offset); + if (link) + printf (" -> %s\n", link); else printf (" [Error reading link]\n"); - if (link) - free (link); + free (link); } else printf ("\n");