From patchwork Tue Feb 23 09:25:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Zhang X-Patchwork-Id: 62681 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1728741lbl; Tue, 23 Feb 2016 01:25:34 -0800 (PST) X-Received: by 10.55.78.198 with SMTP id c189mr40610001qkb.95.1456219532234; Tue, 23 Feb 2016 01:25:32 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 47si22202350qga.86.2016.02.23.01.25.31; Tue, 23 Feb 2016 01:25:32 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 87C31622B2; Tue, 23 Feb 2016 09:25:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 263CA622B3; Tue, 23 Feb 2016 09:25:27 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 2D3B0622B4; Tue, 23 Feb 2016 09:25:25 +0000 (UTC) Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by lists.linaro.org (Postfix) with ESMTPS id 253F6622B2 for ; Tue, 23 Feb 2016 09:25:24 +0000 (UTC) Received: by mail-pa0-f46.google.com with SMTP id yy13so107330540pab.3 for ; Tue, 23 Feb 2016 01:25:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Uq//kpbtohOkBhKkSllCLpS47x36KAu2BmDZq85wIF8=; b=lakOrfejgkq78H03hy8YkeLyx/9hP7NGDiT5EYwxOle1cHlUH+OEkpGx+S4HRabvXc nnuea1MwM47z3wNsWR++z+B4yFzpvXA7Xn4hiC3wFbhlpeG/n0M3RUXCTqMCt0r2xvno nsHFQCDCG4T435/5a0Tk5FfQQH3kUzDric1PG8Bn34oofUL4ntCmG5NGH4NR5J7At025 DYOT8r9ePIVFdJMYXKUB8UYBuafwhfyKx9G9ptVYPoqrcgRBo5wKrK8hD4Q8IoFX1lZt bxIZIBVXzOe8rHbrbsGw3Zps31Cllu1kaHZIJrm46VRef0frOBJTQMI5B8Wtyeq6WkXM Kbww== X-Gm-Message-State: AG10YOQEVViYSULriwxnF7vllcknWf1stp+CzXbb1m8shkBTA2skgPzPxydyiEYlXpH0sLpeNdY= X-Received: by 10.67.1.209 with SMTP id bi17mr44996390pad.150.1456219523534; Tue, 23 Feb 2016 01:25:23 -0800 (PST) Received: from ubuntu1504.ap.freescale.net (gate-zmy3.freescale.com. [192.88.167.1]) by smtp.gmail.com with ESMTPSA id 85sm42583198pfl.18.2016.02.23.01.25.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Feb 2016 01:25:22 -0800 (PST) From: hongbo.zhang@linaro.org To: lng-odp@lists.linaro.org Date: Tue, 23 Feb 2016 17:25:12 +0800 Message-Id: <1456219512-31696-1-git-send-email-hongbo.zhang@linaro.org> X-Mailer: git-send-email 2.1.4 X-Topics: patch Subject: [lng-odp] [PATCH] linux-generic: fix usage of function strncpy X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Hongbo Zhang This is for https://bugs.linaro.org/show_bug.cgi?id=2030: "Memory - illegal accesses (BUFFER_SIZE_WARNING) Calling strncpy with a maximum size argument of 128 bytes on destination array "sysinfo->model_str[id]" of size 128 bytes might leave the destination string unterminated." In fact in the following code there is operation like this: sysinfo->model_str[id][len - 1] = 0 to handle the last character of string, but is is also good to eliminate this coding warning. Signed-off-by: Hongbo Zhang Reviewed-by: Mike Holmes --- platform/linux-generic/arch/mips64/odp_sysinfo_parse.c | 2 +- platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c | 2 +- platform/linux-generic/arch/x86/odp_sysinfo_parse.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c index 53074f7..d45b420 100644 --- a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c @@ -39,7 +39,7 @@ int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo) pos = strchr(str, ':'); strncpy(sysinfo->model_str[id], pos + 2, - sizeof(sysinfo->model_str[id])); + sizeof(sysinfo->model_str[id]) - 1); len = strlen(sysinfo->model_str[id]); sysinfo->model_str[id][len - 1] = 0; model = 1; diff --git a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c index 99457ce..95200ee 100644 --- a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c @@ -38,7 +38,7 @@ int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo) pos = strchr(str, ':'); strncpy(sysinfo->model_str[id], pos + 2, - sizeof(sysinfo->model_str[id])); + sizeof(sysinfo->model_str[id]) - 1); len = strlen(sysinfo->model_str[id]); sysinfo->model_str[id][len - 1] = 0; model = 1; diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c index 816629d..2ef49e4 100644 --- a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c @@ -21,7 +21,7 @@ int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo) if (pos) { pos = strchr(str, ':'); strncpy(sysinfo->model_str[id], pos + 2, - sizeof(sysinfo->model_str[id])); + sizeof(sysinfo->model_str[id]) - 1); pos = strchr(sysinfo->model_str[id], '@'); *(pos - 1) = '\0';