From patchwork Tue Dec 15 04:48:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1416288 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=j3hToG+2; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cw5PH17sNz9sS8 for ; Tue, 15 Dec 2020 15:48:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D1CC385782B; Tue, 15 Dec 2020 04:48:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D1CC385782B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608007708; bh=yEC0tk7Mn6gR20shIGbsBcpJIVYx7BlhUcXi7SJBhN4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=j3hToG+2IAmD/86/667c37xz6guzGgp9ZjzGYI3FylihBzY0ruunNnKId4G1JRVuq 0HjvSK6CBU4HJdpSjSFnYdlpMK+ZMt8wFROm4VRPB5/u3X+wnzyu9X29FGbCsgXJeq pm8Xv2EprW2JCFoxrnZkIIw6gPpQlCfYV/Za7k9E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from dog.elm.relay.mailchannels.net (dog.elm.relay.mailchannels.net [23.83.212.48]) by sourceware.org (Postfix) with ESMTPS id 2C8EB385800D for ; Tue, 15 Dec 2020 04:48:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2C8EB385800D X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id E29543225F6; Tue, 15 Dec 2020 04:48:24 +0000 (UTC) Received: from pdx1-sub0-mail-a35.g.dreamhost.com (100-96-1-8.trex.outbound.svc.cluster.local [100.96.1.8]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 37E96322571; Tue, 15 Dec 2020 04:48:24 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a35.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.18.11); Tue, 15 Dec 2020 04:48:24 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Daffy-Whistle: 318f56bd1d034530_1608007704484_1377702829 X-MC-Loop-Signature: 1608007704484:3243053903 X-MC-Ingress-Time: 1608007704484 Received: from pdx1-sub0-mail-a35.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a35.g.dreamhost.com (Postfix) with ESMTP id CFC5D7F507; Mon, 14 Dec 2020 20:48:23 -0800 (PST) Received: from rhbox.redhat.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a35.g.dreamhost.com (Postfix) with ESMTPSA id AA5617F506; Mon, 14 Dec 2020 20:48:21 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a35 To: libc-alpha@sourceware.org Subject: [PATCH] getmntent: Consolidate character decoding Date: Tue, 15 Dec 2020 10:18:12 +0530 Message-Id: <20201215044812.1068400-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: fweimer@redhat.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The Linux kernel escapes some characters (whitespaces and \) by replacing them with their octal form in the format \xxx. Use that format to decode insteald of looking for specific bytes so that the check is extensible. This way if the kernel escapes additional characters, glibc code won't have to change to accommodate it. I have, for example, proposed[1] to escape the '#' character since it may interfere with parsing in getmntent. The check for '\\\\' is kept intact even though as of today, the kernel does not write '\\\\' to escape a backslash; it write its octal equivalent instead. [1] https://lore.kernel.org/linux-fsdevel/20201215042454.998361-1-siddhesh@gotplt.org/T/#u --- misc/mntent_r.c | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/misc/mntent_r.c b/misc/mntent_r.c index 0e8f10007e..f80b563f39 100644 --- a/misc/mntent_r.c +++ b/misc/mntent_r.c @@ -76,35 +76,22 @@ decode_name (char *buf) char *wp = buf; do - if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '4' && rp[3] == '0') + if (rp[0] == '\\') { - /* \040 is a SPACE. */ - *wp++ = ' '; - rp += 3; - } - else if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '1' && rp[3] == '1') - { - /* \011 is a TAB. */ - *wp++ = '\t'; - rp += 3; - } - else if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '1' && rp[3] == '2') - { - /* \012 is a NEWLINE. */ - *wp++ = '\n'; - rp += 3; - } - else if (rp[0] == '\\' && rp[1] == '\\') - { - /* We have to escape \\ to be able to represent all characters. */ - *wp++ = '\\'; - rp += 1; - } - else if (rp[0] == '\\' && rp[1] == '1' && rp[2] == '3' && rp[3] == '4') - { - /* \134 is also \\. */ - *wp++ = '\\'; - rp += 3; + if (rp[1] == '\\') + { + /* We have to escape \\ to be able to represent all characters. */ + *wp++ = '\\'; + rp += 1; + } + else + { + /* The kernel escapes special characters with their octal + equivalents. */ + char c = 64 * (rp[1] - '0') + 8 * (rp[2] - '0') + rp[3] - '0'; + *wp++ = c; + rp += 3; + } } else *wp++ = *rp;