From patchwork Wed Jul 25 12:03:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hal Rosenstock X-Patchwork-Id: 10543905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E74BB157A for ; Wed, 25 Jul 2018 12:04:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D62E929CF8 for ; Wed, 25 Jul 2018 12:04:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA7DE29D38; Wed, 25 Jul 2018 12:04:03 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE18629CF8 for ; Wed, 25 Jul 2018 12:04:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728757AbeGYNPX (ORCPT ); Wed, 25 Jul 2018 09:15:23 -0400 Received: from mail-qt0-f177.google.com ([209.85.216.177]:45435 "EHLO mail-qt0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728922AbeGYNPX (ORCPT ); Wed, 25 Jul 2018 09:15:23 -0400 Received: by mail-qt0-f177.google.com with SMTP id y5-v6so7272824qti.12 for ; Wed, 25 Jul 2018 05:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dev-mellanox-co-il.20150623.gappssmtp.com; s=20150623; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=OPy0HNh6X8Ww6iNqBa6ky9u9cKpSCC9REkye8Ax7GK0=; b=B/VXRhDYmTVLwE/nLJWTV3oTh5+35EZ/oRSzDuVRN4kZ0DCoVQu1tGJcrrX6n40Qts UgVj73SgUaw4YnrduDJDOyUxJe+wqVqpH6kL+wPS5PQre4B0yP9XCWxXH2YA3Fniyk5z W2ITsdHPb6BeDJwTxtg2OhdWO8MauqYH/HVqTYvFkcybKIALJIwEmLELkqd+CbBdxArk pc56JnIrtNaNj8DVEiXcLW1/Zr5ozg/45dkKsfhO4FA90F420+kONJ6H11IU2h0QDDkv OTxysFPQ+bXgqyo2zdx6EGxhr/6Hx3jzFNeNaahceqZNFgnthQqLkGxX76ScngEyOVM5 GQ8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=OPy0HNh6X8Ww6iNqBa6ky9u9cKpSCC9REkye8Ax7GK0=; b=gq2ox+RXEqtPPNXCbf0TdhJK3M6X1I5P5BT8KJcuon6Ot3P5fH2jSnTZU/QnUv+FEh aN4t9omK9CdRa7g4aceJNTL0LeirOQ/0e95Ufqk3v4Y9J+jkJXWb3juTZD7u7Y80qwyx 2Vme1xDkMBltvgEwxPCgktv5fnxCDWi1clrtGpJc9PROXeUf9ZDqWC3XViVeQ5qPUK26 JGw5ttihPmkGjBSD29QQfcdyU7Y9B6ZIw9egeOH9lP4YhYcAsuJqgF8djZbEAWdSnVHe iH7p4N4U4W3S87/uJv2g8otVS2mFGQsuGUrr5VCytWocna7WpjcAxr1orClgubqDM13K viig== X-Gm-Message-State: AOUpUlGv1teMUuZUa8zIWT8kSesHk6Wfo5U0AEbokYo17kdGcH/zQ0mL DU/rbMJyoaTnTn6VN1K6qgqmQdXj9Rw= X-Google-Smtp-Source: AAOMgped/BWjuBZPkpqxl8fIgs6Q/Pstz5ycPxOw9BtrE13AL9ld4/CyV1CbaWlRFsqa9ANdaky5kg== X-Received: by 2002:ac8:855:: with SMTP id x21-v6mr20202159qth.42.1532520239125; Wed, 25 Jul 2018 05:03:59 -0700 (PDT) Received: from [192.168.1.183] (c-73-142-227-196.hsd1.ma.comcast.net. [73.142.227.196]) by smtp.googlemail.com with ESMTPSA id q15-v6sm12873198qte.55.2018.07.25.05.03.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jul 2018 05:03:58 -0700 (PDT) To: Honggang LI Cc: "linux-rdma@vger.kernel.org" From: Hal Rosenstock Subject: [PATCHv2 opensm] osm_console_io.c: Avoid potential no NUL-terminated strncpy in osm_console_init Message-ID: <83baceda-a0fb-e8e6-5f20-3bd9117a3e80@dev.mellanox.co.il> Date: Wed, 25 Jul 2018 08:03:57 -0400 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Language: en-US Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The default string of opt-console is OSM_DEFAULT_CONSOLE, which equal "off". It is safe to copy 32 bytes in ‘osm_console_init’, when the 'console' field was initialized with default value. But this minor fix avoids potential no NUL-terminated strncpy. make[2]: Entering directory '/home/honli/upstream-repos/opensm/opensm' depbase=`echo osm_console_io.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\ gcc -DHAVE_CONFIG_H -I. -I../include -I../include/opensm -I./../include -I./../../libibumad/include -I/usr/local/include -Werror -Wall -Wwrite-strings -g -D_XOPEN_SOURCE=600 -D_DEFAULT_SOURCE=1 -g -O2 -MT osm_console_io.o -MD -MP -MF $depbase.Tpo -c -o osm_console_io.o osm_console_io.c &&\ mv -f $depbase.Tpo $depbase.Po osm_console_io.c: In function ‘osm_console_init’: osm_console_io.c:186:2: error: ‘strncpy’ specified bound 32 equals destination size [-Werror=stringop-truncation] strncpy(p_oct->client_type, opt->console, sizeof(p_oct->client_type)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Signed-off-by: Honggang Li Signed-off-by: Hal Rosenstock Acked-by: Honggang Li --- opensm/osm_console_io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/opensm/osm_console_io.c b/opensm/osm_console_io.c index f529e25..97fe674 100644 --- a/opensm/osm_console_io.c +++ b/opensm/osm_console_io.c @@ -182,7 +182,8 @@ void osm_console_prompt(FILE * out) int osm_console_init(osm_subn_opt_t * opt, osm_console_t * p_oct, osm_log_t * p_log) { p_oct->socket = -1; - strncpy(p_oct->client_type, opt->console, sizeof(p_oct->client_type)); + strncpy(p_oct->client_type, opt->console, sizeof(p_oct->client_type) - 1); + p_oct->client_type[sizeof(p_oct->client_type) - 1] = '\0'; /* set up the file descriptors for the console */ if (strcmp(opt->console, OSM_LOCAL_CONSOLE) == 0) {