From patchwork Sun Dec 4 09:21:56 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: 702405 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 3tWj8L471Gz9sxS for ; Sun, 4 Dec 2016 20:22:10 +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="nIsgtXI5"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 9AE8B88090; Sun, 4 Dec 2016 09:22:06 +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 OzvzeuMn3bQ5; Sun, 4 Dec 2016 09:22:05 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 810EE88085; Sun, 4 Dec 2016 09:22:05 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 82E511C0479 for ; Sun, 4 Dec 2016 09:22:01 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 713CF87FEB for ; Sun, 4 Dec 2016 09:22:01 +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 ZUYVSKv2PtA1 for ; Sun, 4 Dec 2016 09:22:00 +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 hemlock.osuosl.org (Postfix) with ESMTPS id 60FB28800D for ; Sun, 4 Dec 2016 09:22:00 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id m203so9120499wma.3 for ; Sun, 04 Dec 2016 01:22:00 -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=3tpGL3cbbfD1HA2l4tiAx6imPen39llPCGfJ2wOyu0o=; b=nIsgtXI5e9qixBnGH89ocyqKKUEes1FMJovVdeePUUr/p3FZC/B2eJsKOcwPpoOi32 EAW/DmXliVGJXn5a/Rh5IRLn7vOxDf5PqHkYhZPUTvwd3q8ppKKQH1GidOPi+tCrr03X 3C2fQQk40q0ZqyDMxBY+jsUZjCr6AQqNyFu62k4U/qOOZial6y6HXxpb9ns1+LmADIj4 khbwhhfsF/gsd96HTh+XdDd5JEoAQAyIpYRSbZqN6H+yzLAaJVfq6ZjYwiGSonnc/SAV pUo59BmBxaFFMWrd8WUlgOpOeEueRyI8xdtl01xY8J3pSx1UhV/Sypau9uUKC/J8sbsy EFug== 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=3tpGL3cbbfD1HA2l4tiAx6imPen39llPCGfJ2wOyu0o=; b=JsJRetAb9ltm5sIuzh6+rpBqvoG5b69Th8AfsXjj75FiXxrH518zzkFYoNc3rO+J4Y NpnxuVJZRoe8WqSzA1sm6WOoRWJzBztVNOGstNtsnaCGLaeq4+gszpnm/jTw89lsoO4H 8yTXncfMs/OncXJY4bxlfxwxzsQpExxaZ/aW8O1aHzPTt3guZbLHojkptIwtNrKJPiNv sgNVUGEe7Y7Nda8eJ0QLLCnbEhFgryF3zHGR3i0YFtf1ZTgxJKzLa3l9vO3y2+R1F7JN 4Jw4RiWEmRQJmfZHcmNQ9aPkoMWNNHUghCqY6po04hsPrhmXJUdpoI+GVnZ/E7AatpRB ZDbg== X-Gm-Message-State: AKaTC00NmJZE36KovFPoRHMvE2e5H5/tdXBamxx/N9UGt3zOr1g7ctwwYBN3n8AmrUpTSg== X-Received: by 10.28.17.205 with SMTP id 196mr4362646wmr.78.1480843318745; Sun, 04 Dec 2016 01:21:58 -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.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 04 Dec 2016 01:21:58 -0800 (PST) From: "Yann E. MORIN" To: buildroot@buildroot.org Date: Sun, 4 Dec 2016 10:21:56 +0100 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: Cc: Thomas Petazzoni , "Yann E. MORIN" Subject: [Buildroot] [PATCH 2/2] toolchain/wrapper: use the {str, len} tuples for the unsafe paths 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 pased to gcc, to avoid hard-coding an ever-growing, long list of those args directly in the condition check. Now, we're left with a long list of unsafe paths, somehow hidden within the code, which can use the same mechanism we use for arguments. Signed-off-by: "Yann E. MORIN" Cc: Thomas Petazzoni --- toolchain/toolchain-wrapper.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/toolchain/toolchain-wrapper.c b/toolchain/toolchain-wrapper.c index 8bc0007..100aa18 100644 --- a/toolchain/toolchain-wrapper.c +++ b/toolchain/toolchain-wrapper.c @@ -98,6 +98,20 @@ struct str_len_s { */ #define STR_LEN(s) { #s, sizeof(#s)-1 } +/* List of paths considered unsafe for cross-compilation. + * + * An unsafe path is one that points to a directory with libraries or + * headers for the build machine, which are not suitable for the target. + */ +static const struct str_len_s unsafe_paths[] = { + STR_LEN(/lib), + STR_LEN(/usr/include), + STR_LEN(/usr/lib), + STR_LEN(/usr/local/include), + STR_LEN(/usr/local/lib), + { NULL, 0 }, +}; + /* Unsafe options are options that specify a potentialy unsafe path, * that will be checked by check_unsafe_path(), below. */ @@ -126,13 +140,10 @@ static void check_unsafe_path(const char *arg, int paranoid, int arg_has_path) { - char **c; - static char *unsafe_paths[] = { - "/lib", "/usr/include", "/usr/lib", "/usr/local/include", "/usr/local/lib", NULL, - }; + const struct str_len_s *p; - for (c = unsafe_paths; *c != NULL; c++) { - if (strncmp(path, *c, strlen(*c))) + for (p=unsafe_paths; p->str; p++) { + if (strncmp(path, p->str, p->len)) continue; fprintf(stderr, "%s: %s: unsafe header/library path used in cross-compilation: '%s%s%s'\n",