From patchwork Fri Jun 22 11:54:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Crequy X-Patchwork-Id: 10481939 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CA64560230 for ; Fri, 22 Jun 2018 11:55:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF18D28E75 for ; Fri, 22 Jun 2018 11:55:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B128C28EA6; Fri, 22 Jun 2018 11:55:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 506A528E75 for ; Fri, 22 Jun 2018 11:55:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751206AbeFVLzf (ORCPT ); Fri, 22 Jun 2018 07:55:35 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:39284 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751005AbeFVLze (ORCPT ); Fri, 22 Jun 2018 07:55:34 -0400 Received: by mail-ed1-f67.google.com with SMTP id w14-v6so1068738eds.6; Fri, 22 Jun 2018 04:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=XBDyPySvKMlqQ+2G09cNa+x4o+CPAuNB+70mQR2OJUc=; b=fFprOpWEE4Ki9kiaawljO7THILgFRPytGusc4nwEMdT2itMcGJGir8/yXBwggYhon+ 034aeCHIN1iclThvXNy5ut4gaw9eXw955pk/7Sk1vp+oDzEfQuNRAel8gut0uQKIdXJn wE13r6bN9IZtqN5RkEj2QVd46BvO0R21MLbC1zOy0DsSZmCcp6TfmYMgQhb68qGLQOgY aMZQV8yA/8e07EMwJoP2DH/aYbFPrFnm/gKCN6raymPGb/h5g7zAiO9QklYcT3Sgobvc gnT3QkRXRm9uTslEpQWL2VCaKuqH9B+BxA43cVZO7Er6fILkRPDTXCXmLaagutDOi91N ixsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=XBDyPySvKMlqQ+2G09cNa+x4o+CPAuNB+70mQR2OJUc=; b=M2RxW5zjoQGtHnhnNOfbTWSJ4qj1oolS0aUX9ExdeF7IrJfdl9X3K0jVImYUmUlNtq +viHCsppngRauwZjm6fe0z66mvMOhYCbnhsS35mN/Dz8WxeIYtcgNMXgWwZ+GSKXseWs 5QGH/TuKJX6uHBM6QEx6wHi7vbtoSpJ/flS/xO1ksdYUUGZL5IWmWHyFKBA+N5wEBmPK MKKCKJGE/GR1isdMu6Bts98Y94cazgMnvVpghW19IEmK8wJHQX2f5Qy1jbPbpITa36LR DnHp8h28FoCtaMmGk5eiyt1F4t26RU7FGRyJ4ZhHVgYBTwpj0uXO/kbfJwtAS/SPPMHP UCqQ== X-Gm-Message-State: APt69E2Q7qKq85K7CU/CMxPdy9AgkucT2w6RyKGNDL3zsOVU25Fi1OOU 1qKSkIj8V7/t5+NIh3of/ts= X-Google-Smtp-Source: ADUXVKLxxLyN7XzlQCMwrug9252iRGZ3JYECUumBxVbCTUkUn3oib/IwraVK0Wzwn9FM8AbevMBhUg== X-Received: by 2002:a50:b286:: with SMTP id p6-v6mr1639494edd.22.1529668533291; Fri, 22 Jun 2018 04:55:33 -0700 (PDT) Received: from neptune.fritz.box ([178.19.216.175]) by smtp.gmail.com with ESMTPSA id s2-v6sm4926649edm.13.2018.06.22.04.55.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Jun 2018 04:55:32 -0700 (PDT) From: Alban Crequy X-Google-Original-From: Alban Crequy To: Karel Zak , util-linux@vger.kernel.org, Alban Crequy Cc: linux-fsdevel@vger.kernel.org, dongsu@kinvolk.io Subject: [PATCH] mountinfo: parse empty strings in source Date: Fri, 22 Jun 2018 13:54:25 +0200 Message-Id: <20180622115425.26183-1-alban@kinvolk.io> X-Mailer: git-send-email 2.14.3 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Alban Crequy The source of a mount in /proc/self/mountinfo can unfortunately be an empty string. Before this patch, 'mount' and 'mountpoint' fail as following: $ sudo mount -t tmpfs "" /tmp/bb $ mount mount: /proc/self/mountinfo: parse error at line 64 -- ignored $ mountpoint /tmp/bb /tmp/bb is not a mountpoint This patch fixes the parsing. It is unfortunately more complex because sscanf() does not handle fields with empty strings easily. Other projects have their own parser for mountinfo and have similar issues. I know of runc and runtime-tools (I'll send a patch for those two) but there are probably others. Signed-off-by: Alban Crequy --- libmount/src/tab_parse.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 3ed84ebc2..4944d5f8c 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -173,13 +173,36 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) fs->opt_fields = strndup(s + 1, p - s - 1); s = p + 3; - rc += sscanf(s, UL_SCNsA" " /* (8) FS type */ - UL_SCNsA" " /* (9) source */ - UL_SCNsA, /* (10) fs options (fs specific) */ + end = 0; + rc += sscanf(s, UL_SCNsA"%n", /* (8) FS type */ &fstype, - &src, - &fs->fs_optstr); + &end); + + if (rc >= 8 && end > 0) + s += end; + if (s[0] == ' ') + s++; + + /* (9) source can unfortunately be an empty string "" and scanf does + * not work well with empty string. Test with: + * $ sudo mount -t tmpfs "" /tmp/bb + * $ mountpoint /tmp/bb + * */ + if (s[0] == ' ') { + src = strdup(""); + s++; + rc++; + rc += sscanf(s, UL_SCNsA, /* (10) fs options (fs specific) */ + + &fs->fs_optstr); + } else { + rc += sscanf(s, UL_SCNsA" " /* (9) source */ + UL_SCNsA, /* (10) fs options (fs specific) */ + + &src, + &fs->fs_optstr); + } if (rc >= 10) { size_t sz;