From patchwork Tue Mar 12 13:30:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1055398 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uGGfHi1C"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="wo874/+C"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44JbTK1xtfz9s7h for ; Wed, 13 Mar 2019 00:31:01 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=U7XDBIBBc48MYWT2WequINDI9XsAX5BbI1cV1z/Mc6k=; b=uGGfHi1CbT+Elt x7FzSanACeJSQ/eHjL6IZgjCENUZj9DLx+PQ+b4ZTUBWy8r4p0lVpYKJOSm6VumJsSDc0Pz/5+yVq Td11dE5gBNd4XMuLLbNH2L9XJoL/N6/wWMdAlzpkT7aKKKspydBD1k9bDe2akCtWuPgyfEz6QHt7R RIQst1H5PQI04PpEiPoa3WyPr1VovKVCEaFb2kZkPI9P+S50ihlij/Nx8K0R1uOQOLuGCN6lLs7ZI QSMFImwXIu+eb1yjHKyb5kaRfv7w+6orDMFbgLp736KX+7WblGT0gGbwAStejsGcvusYukEGYuZ57 hmz3aNAdw3DOsRoIMXwg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h3hUc-0003mw-05; Tue, 12 Mar 2019 13:30:54 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h3hUZ-0003mW-L7 for linux-um@lists.infradead.org; Tue, 12 Mar 2019 13:30:53 +0000 Received: by mail-wm1-x344.google.com with SMTP id x10so2616812wmg.2 for ; Tue, 12 Mar 2019 06:30:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3QIFQocTUGRi3zH5QMDviZrJx7jR9iM8LInODOvNKNg=; b=wo874/+Csl+843lZ8Q25PESj1oWghoL6/zdckFhhIAXku6KT3/mVk6KqVfPwRzppbS IhgeORiHg5GQaNE02CxPxabvmVRZkJ+6Qo1bZsp/A+Djxyndw801RfXFVdawM6l4rFo/ 2D5C2WN35wCkf0aF7YUQNEkUzp7w5914lWLKTMAd08yxy89UAAZ2bnRUHHOb5KJZAJ5a n0CuMj82Y8WLvbbfOnxjbv3uxM9F7n1IEE0EHIf2lUAhkWyvMM6fcpFqaoji/+44/qxL A2+Hbtj5HiCnuRvULGpPuSRDoaT3ELCux0vcCGCYp7AdQ+O5ltC7vdvMZ5UQec927pS5 Hspg== 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:mime-version :content-transfer-encoding; bh=3QIFQocTUGRi3zH5QMDviZrJx7jR9iM8LInODOvNKNg=; b=OaL3mNCizjkzPrEWdAijWiwun4e6e6Cjx2Wnd+fp0e5QSkiEuCSznnyrJyjckecxlM sAdoeQbK7+Cj9kX81f2IYJx7+71dz5gMxQiBk3osDv5LJATGYfjopsR0hIk7FH0u2Ozx x2fYefaYJBJwPLRm6E30uWBtL2N3Q9V9U00Ox8sv6zXDJtluiuONkP8tf2KqvcDa9QSK zMT9nsPQKqQDqUu5g1QC6OOwRRuymuA4UYbnYD9m74wkQT7TjgjggtbiYV5q7Ho8EWjz QMBVaY7ZpkQhVnsvxteq9zHJNu2KU+m4LuFaClPv362D0GO7n5XK3s6jA7clf4rUKGWO 2TDA== X-Gm-Message-State: APjAAAUdbXXvhe1ZjX6sSKdReo7ksvvP6AZwZfxYvujbuYQ7GjlG8hzZ vvpc+TkJFv4yBg20Iwtim0nSdg== X-Google-Smtp-Source: APXvYqyAMTX7z+yeTXqDQ8Ln41XysN9xVrOYSMJH6OspoNeU6Bb/lI/HwSYEIAnHAfHiVYCO+wIomQ== X-Received: by 2002:a1c:3c02:: with SMTP id j2mr2587786wma.72.1552397450001; Tue, 12 Mar 2019 06:30:50 -0700 (PDT) Received: from localhost.localdomain (aputeaux-684-1-27-140.w90-86.abo.wanadoo.fr. [90.86.252.140]) by smtp.gmail.com with ESMTPSA id p5sm2187849wme.14.2019.03.12.06.30.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 06:30:49 -0700 (PDT) From: Bartosz Golaszewski To: Jeff Dike , Richard Weinberger , Anton Ivanov Subject: [PATCH] um: remove uses of variable length arrays Date: Tue, 12 Mar 2019 14:30:47 +0100 Message-Id: <20190312133047.16201-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190312_063051_692145_437FA466 X-CRM114-Status: GOOD ( 12.92 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:344 listed in] [list.dnswl.org] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_MED DKIMwl.org - Whitelisted Medium sender X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bartosz Golaszewski , linux-um@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Bartosz Golaszewski While the affected code is run in user-mode, the build still warns about it. Convert all uses of VLA to dynamic allocations. Signed-off-by: Bartosz Golaszewski --- arch/um/os-Linux/umid.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/arch/um/os-Linux/umid.c b/arch/um/os-Linux/umid.c index 998fbb445458..e261656fe9d7 100644 --- a/arch/um/os-Linux/umid.c +++ b/arch/um/os-Linux/umid.c @@ -135,12 +135,18 @@ static int remove_files_and_dir(char *dir) */ static inline int is_umdir_used(char *dir) { - char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; - char pid[sizeof("nnnnn\0")], *end; + char pid[sizeof("nnnnn\0")], *end, *file; int dead, fd, p, n, err; + size_t filelen; - n = snprintf(file, sizeof(file), "%s/pid", dir); - if (n >= sizeof(file)) { + err = asprintf(&file, "%s/pid", dir); + if (err < 0) + return 0; + + filelen = strlen(file); + + n = snprintf(file, filelen, "%s/pid", dir); + if (n >= filelen) { printk(UM_KERN_ERR "is_umdir_used - pid filename too long\n"); err = -E2BIG; goto out; @@ -185,6 +191,7 @@ static inline int is_umdir_used(char *dir) out_close: close(fd); out: + free(file); return 0; } @@ -210,18 +217,21 @@ static int umdir_take_if_dead(char *dir) static void __init create_pid_file(void) { - char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; - char pid[sizeof("nnnnn\0")]; + char pid[sizeof("nnnnn\0")], *file; int fd, n; - if (umid_file_name("pid", file, sizeof(file))) + file = malloc(strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")); + if (!file) return; + if (umid_file_name("pid", file, sizeof(file))) + goto out; + fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0644); if (fd < 0) { printk(UM_KERN_ERR "Open of machine pid file \"%s\" failed: " "%s\n", file, strerror(errno)); - return; + goto out; } snprintf(pid, sizeof(pid), "%d\n", getpid()); @@ -231,6 +241,8 @@ static void __init create_pid_file(void) errno); close(fd); +out: + free(file); } int __init set_umid(char *name) @@ -385,13 +397,19 @@ __uml_setup("uml_dir=", set_uml_dir, static void remove_umid_dir(void) { - char dir[strlen(uml_dir) + UMID_LEN + 1], err; + char *dir, err; + + dir = malloc(strlen(uml_dir) + UMID_LEN + 1); + if (!dir) + return; sprintf(dir, "%s%s", uml_dir, umid); err = remove_files_and_dir(dir); if (err) os_warn("%s - remove_files_and_dir failed with err = %d\n", __func__, err); + + free(dir); } __uml_exitcall(remove_umid_dir);