From patchwork Sun Dec 4 09:21:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yann E. MORIN" X-Patchwork-Id: 702404 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tWj8G6GvQz9sxS for ; Sun, 4 Dec 2016 20:22:06 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="F7lsdmEe"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id B77378800A; Sun, 4 Dec 2016 09:22:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8xTf6wK62fCu; Sun, 4 Dec 2016 09:22:02 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 095338800D; Sun, 4 Dec 2016 09:22:02 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 7FCAC1C0479 for ; Sun, 4 Dec 2016 09:22:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 7ABCC865F5 for ; Sun, 4 Dec 2016 09:22:00 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id V4Y9PvnurVOV for ; Sun, 4 Dec 2016 09:21:59 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 93C65862C6 for ; Sun, 4 Dec 2016 09:21:59 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id a20so9177624wme.2 for ; Sun, 04 Dec 2016 01:21:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=qNREXZKBF9wkoVXpjCxEbX5e9FGhbkjbyp95Iyta768=; b=F7lsdmEeosZnZjLrSiozOhySRDWAxUitVq2pYYRnJGcZASR3Q/hUAMkntZylq0eWGU vcyRNGq5/Va6ZeMgQvI+EJkK79MlV3ukARahBBvWhQEKhZsn1zHP6YDjWfppdS3rUZF4 glydFN7nzJvYHaqdrc1AFQugMLwkEeD6eyl+oC1eRwENi06yfEp0oHsZsCjbKT8gZpqX APi3RrqKE5/8O3vVZkwBtwVcDZrrS+KRlqty/G/A5mEE8f1C7SHcWrsuWUmT+JctbJ5g 43FkpGbyfXuz3+RDBrA+6UEY0iwzE48+0/zgtk+j3HOZGgSyP6PogytHg0csc4BgGXrs 1NQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=qNREXZKBF9wkoVXpjCxEbX5e9FGhbkjbyp95Iyta768=; b=GSMV7gp5dbrDy2gVEOruNlv0qGrr70Fa+bUvkNmm82hI1ci1QKORWEqP8+MuXT+HVq 5TpxuqQ6agiAldRL8gWyxumb8B9UCitOsIztTI/kYZlNT+LZ4de6szQhTf7UmJkITZ6+ BHDI6HP9Wr2r8W5n+WJcdilr4kcXSpEJmriGzLqmLyuKjAjnVNwsg4xtLXSjgv2ghltx JehAt8E+2t4bcfRw9D0mIASxbCi5VYzQhmezIitR8zCK22+7dHIFjIszHipYwMfSJI0K wnNVqaZHMr9q4ellu4IA5zI0+Tnj6VOYYPIWJaJI6uo5xsoEzDldKy53rvNQYMeXUoiy 0Nlg== X-Gm-Message-State: AKaTC00n7saEbrVSb46QZRXzQ4HBeAxEz+60Y4pa0xhpDb+gMbTWYxLiiurvAMEQCWIRiA== X-Received: by 10.28.157.200 with SMTP id g191mr4305731wme.33.1480843317856; Sun, 04 Dec 2016 01:21:57 -0800 (PST) Received: from gourin.bzh.lan (ns304657.ip-46-105-103.eu. [46.105.103.66]) by smtp.gmail.com with ESMTPSA id 135sm12161795wmh.14.2016.12.04.01.21.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 04 Dec 2016 01:21:57 -0800 (PST) From: "Yann E. MORIN" To: buildroot@buildroot.org Date: Sun, 4 Dec 2016 10:21:55 +0100 Message-Id: <3abc018c4876797dca8dd8ae8b92f5de6d014ac1.1480843290.git.yann.morin.1998@free.fr> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: Cc: Thomas Petazzoni , "Yann E. MORIN" Subject: [Buildroot] [PATCH 1/2] toolchain/wrapper: make the {str, len} tuple more generic, add comments X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" In 61cb120 (toolchain/wrapper: extend paranoid check to -isystem), we introduced a {str,len} tuple to check the various arguments passed to gcc, to avoid hard-coding an ever-growing, long list of those args directly in the condition check. It was made specific to the arguments (the structure member is named 'arg'), but can also be used to store the unsafe paths as well. Also, that piece is almost un-documented. Rename the structure member so that it is more generic, and add a bit of comments to explain the whole of it. Signed-off-by: "Yann E. MORIN" Cc: Thomas Petazzoni --- toolchain/toolchain-wrapper.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/toolchain/toolchain-wrapper.c b/toolchain/toolchain-wrapper.c index d59629b..8bc0007 100644 --- a/toolchain/toolchain-wrapper.c +++ b/toolchain/toolchain-wrapper.c @@ -83,23 +83,30 @@ static char *predef_args[] = { #endif }; -struct unsafe_opt_s { - const char *arg; +/* A {string,length} tuple, to avoid computing strlen() on constants. + * - str must be a \0-terminated string + * - len does not account for the terminating '\0' + */ +struct str_len_s { + const char *str; size_t len; }; +/* Define a {string,length} tuple. Takes an unquoted constant string as + * parameter. sizeof() on a string literal includes the terminating \0, + * but we don't want to count it. + */ +#define STR_LEN(s) { #s, sizeof(#s)-1 } + /* Unsafe options are options that specify a potentialy unsafe path, * that will be checked by check_unsafe_path(), below. - * - * sizeof() on a string literal includes the terminating \0. */ -#define UNSAFE_OPT(o) { #o, sizeof(#o)-1 } -static const struct unsafe_opt_s unsafe_opts[] = { - UNSAFE_OPT(-I), - UNSAFE_OPT(-idirafter), - UNSAFE_OPT(-iquote), - UNSAFE_OPT(-isystem), - UNSAFE_OPT(-L), +static const struct str_len_s unsafe_opts[] = { + STR_LEN(-I), + STR_LEN(-idirafter), + STR_LEN(-iquote), + STR_LEN(-isystem), + STR_LEN(-L), { NULL, 0 }, }; @@ -262,10 +269,10 @@ int main(int argc, char **argv) /* Check for unsafe library and header paths */ for (i = 1; i < argc; i++) { - const struct unsafe_opt_s *opt; - for (opt=unsafe_opts; opt->arg; opt++ ) { + const struct str_len_s *opt; + for (opt=unsafe_opts; opt->str; opt++ ) { /* Skip any non-unsafe option. */ - if (strncmp(argv[i], opt->arg, opt->len)) + if (strncmp(argv[i], opt->str, opt->len)) continue; /* Handle both cases: