From patchwork Sun Jun 17 00:34:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10468113 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 EB075600CC for ; Sun, 17 Jun 2018 00:34:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8D33288E4 for ; Sun, 17 Jun 2018 00:34:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD06528AE6; Sun, 17 Jun 2018 00:34:20 +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=-5.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8670B288E4 for ; Sun, 17 Jun 2018 00:34:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F3B4A6E30E; Sun, 17 Jun 2018 00:34:19 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qk0-x241.google.com (mail-qk0-x241.google.com [IPv6:2607:f8b0:400d:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 24F3D6E30E; Sun, 17 Jun 2018 00:34:19 +0000 (UTC) Received: by mail-qk0-x241.google.com with SMTP id 185-v6so7646276qkk.11; Sat, 16 Jun 2018 17:34:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=mA96Ap7Xwdfik3IUxC2U8dJXlJgUKYc6Dlw6eeyLUFI=; b=AjJsd8N3ORJVGUI9v8j+NJMQ/0pdhGa59U8Eazl5cSra3uVpCGR/9ip1C1GtQws/fY R1MYVp7Fjrj/LNoC6PEoDwiycgAc4KduSOG1Y9ijyToRnPlXHdnFZYU/3jiN9I3ga19y 5hXn/DdK0a4Y3UgIuaJjNbrlUYOVnJQTylQlv/EbnkM2vAnhZudTxxoWkmVsQMvfpDZX B8xpJgxVCjSVv4AgEF8rNah5ckNVSbeKwMLw104DMk/SjYe3aH7MUMdyecmjaDiRHf/X 7/sLKkYvJ/x2l00P/u7SZ5PNkvGhX3s2ba0O8009DSsM9lFwi4LxvEl6jtlVqDCsqxLA +zHg== X-Gm-Message-State: APt69E1hJlepihnLgSp5bJHmQEL61b7r0kMaRcdHpLLA5r8JMZZXLzYC yu+Ky0df22tWvk8AVX/9JEc= X-Google-Smtp-Source: ADUXVKK3hjBVAyC7jurcv1mO8DYFb0pZbyTzIPzzmS1P2mCXv5kLZ0wCn+3zJ1mhkxNWDRcoOLm9Ng== X-Received: by 2002:a37:4e8c:: with SMTP id c134-v6mr5744701qkb.207.1529195658291; Sat, 16 Jun 2018 17:34:18 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id b2-v6sm10479226qkb.34.2018.06.16.17.34.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 16 Jun 2018 17:34:17 -0700 (PDT) Date: Sat, 16 Jun 2018 21:34:14 -0300 From: Rodrigo Siqueira To: Petri Latvala , Arkadiusz Hiler Message-ID: <612d8c584cd1fd33b139982ae42771650907f062.1529175003.git.rodrigosiqueiramelo@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180512 Subject: [Intel-gfx] [PATCH V2 i-g-t 1/3] Avoid truncate string in __igt_lsof_fds X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Note that 'proc_path' parameter in __igt_lsof_fds receives a string which was initialized with the size of PATH_MAX and the local variable 'path' has the same size, but it also have to append: '/', '\0', and the directory name. This situation caused the warning described below. warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Wformat-truncation=] snprintf(path, sizeof(path), "%s/%s", proc_path, d->d_name); note: ‘snprintf’ output between 2 and 4352 bytes into a destination of size 4096 [..] This commit fixes this problem by changing the string size passed by __igt_lsoft to __igt_lsof_fds; basically, the max size for the string is calculated in a directive and then used to declare the array. Signed-off-by: Rodrigo Siqueira --- lib/igt_aux.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index acafb713..1ea52efe 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -48,6 +48,8 @@ #include #include #include +#include +#include #include #include @@ -71,6 +73,8 @@ #include /* for dirname() */ #endif +#define MAX_CWD_LEN (unsigned int)(sizeof("/proc//cwd") + ceil(log10(INT_MAX))) + /** * SECTION:igt_aux * @short_description: Auxiliary libraries and support functions @@ -1485,7 +1489,7 @@ __igt_lsof(const char *dir) PROCTAB *proc; proc_t *proc_info; - char path[PATH_MAX]; + char path[MAX_CWD_LEN]; char *name_lnk; struct stat st; int state = 0;