From patchwork Sat Jul 7 23:23:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10512979 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 DBFF6600CA for ; Sat, 7 Jul 2018 23:23:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB61C288E1 for ; Sat, 7 Jul 2018 23:23:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFB8C288EA; Sat, 7 Jul 2018 23:23:58 +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 5C344288E1 for ; Sat, 7 Jul 2018 23:23:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DD07C6E35C; Sat, 7 Jul 2018 23:23:57 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qt0-x241.google.com (mail-qt0-x241.google.com [IPv6:2607:f8b0:400d:c0d::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 08A736E35C; Sat, 7 Jul 2018 23:23:57 +0000 (UTC) Received: by mail-qt0-x241.google.com with SMTP id f18-v6so12807741qtp.10; Sat, 07 Jul 2018 16:23:56 -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=qWulBcJA8mNkKsX6sk04KA2/yNPHjGKx2A+CE/LORkY=; b=PhNce2PAv5mNOgKH8vI1Gue+SWCzzMBXH5otZd7BxMEk8+JnDcbUunyLEkUK0TY/wV BathU7YzKMvE2c3sYAsXlFfAYL1nW2v6Q/mzGYwGXecDqHxK55pZfnplhuXNPh5fBkBA 7Lqah1OIEkCXfaUGYcpWK6Cbiqq0dsMzf/fHt5m7Xog+8+ZjuR13Ol7+zyLKRDrGaCyQ Hnc5dWd4Lco/Wt9z2J/AXWekEJMd0CF0IXsb7qfn4V4R4EciiDuLQRvI3ObZFXqqBRfi tOzZclxJEhtOydroIYe6f1v0uCsAZOLsh3+mkmNIJB6dHN96LaWnEEz8yuFWlK0O+vGq GTfQ== X-Gm-Message-State: APt69E2hvX/yDXea81H8KSRQXdMkqu7X11XG5XSkK9N5/HsVkhiW7YYT yFRQ1T/bha9If2SPqrXqkh/m3w== X-Google-Smtp-Source: AAOMgpeUn5FarLV4SNvgCzNXB77HVMDbdZhohtN9wxske3Ud9q6FQJCNyl0OWwH6LlZmPWpmVVQaTQ== X-Received: by 2002:ac8:3415:: with SMTP id u21-v6mr13628405qtb.391.1531005836244; Sat, 07 Jul 2018 16:23:56 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id l73-v6sm13045332qkl.78.2018.07.07.16.23.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 07 Jul 2018 16:23:55 -0700 (PDT) Date: Sat, 7 Jul 2018 20:23:53 -0300 From: Rodrigo Siqueira To: Petri Latvala , Arkadiusz Hiler Message-ID: <3ba3f46a744f6ccff7c0af61c57d5db7be2d7c3a.1531005542.git.rodrigosiqueiramelo@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180622 Subject: [Intel-gfx] [PATCH i-g-t 7/7] 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. The max size for the string is strlen("/proc/%d/cwd")+1 where "%d" can be estimated with CEILING(LOG_10(INT_MAX)), in this sense, it is safe to define a path size of 30 characters. Signed-off-by: Rodrigo Siqueira --- lib/igt_aux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index ca8ccfbd..d9dbf7ce 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -1485,7 +1485,7 @@ __igt_lsof(const char *dir) PROCTAB *proc; proc_t *proc_info; - char path[PATH_MAX]; + char path[30]; char *name_lnk; struct stat st; int state = 0;