From patchwork Fri Oct 12 11:54:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggang LI X-Patchwork-Id: 10638579 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 68D111508 for ; Fri, 12 Oct 2018 11:55:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 543C42BB01 for ; Fri, 12 Oct 2018 11:55:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42D132BB06; Fri, 12 Oct 2018 11:55:05 +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.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 E8D262BB01 for ; Fri, 12 Oct 2018 11:55:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728424AbeJLT1J (ORCPT ); Fri, 12 Oct 2018 15:27:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32108 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728040AbeJLT1J (ORCPT ); Fri, 12 Oct 2018 15:27:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFC41E1EE1; Fri, 12 Oct 2018 11:55:03 +0000 (UTC) Received: from lhg.nay.redhat.com (unknown [10.66.129.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 753C58497C; Fri, 12 Oct 2018 11:55:02 +0000 (UTC) From: Honggang LI To: hal@dev.mellanox.co.il Cc: linux-rdma@vger.kernel.org, Honggang Li Subject: [opensm patch] Use precision specifier for scanf Date: Fri, 12 Oct 2018 19:54:56 +0800 Message-Id: <20181012115456.3780-1-honli@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 12 Oct 2018 11:55:03 +0000 (UTC) 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 From: Honggang Li If user input a string larger than the length of buffer, the stack memory will be corrupted. Signed-off-by: Honggang Li --- opensm/main.c | 2 +- osmtest/osmtest.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/opensm/main.c b/opensm/main.c index 2d23fe2b..8def799c 100644 --- a/opensm/main.c +++ b/opensm/main.c @@ -499,7 +499,7 @@ static ib_net64_t get_port_guid(IN osm_opensm_t * p_osm, uint64_t port_guid) fflush(stdout); if (scanf("%u", &choice) <= 0) { char junk[128]; - if (scanf("%s", junk) <= 0) + if (scanf("%127s", junk) <= 0) printf("\nError: Cannot scan!\n"); } else if (choice == 0) return 0; diff --git a/osmtest/osmtest.c b/osmtest/osmtest.c index 281b247a..fa2e0704 100644 --- a/osmtest/osmtest.c +++ b/osmtest/osmtest.c @@ -7352,7 +7352,7 @@ osmtest_get_user_port(IN osmtest_t * const p_osmt, fflush(stdout); if (scanf("%u", &choice) <= 0) { char junk[256]; - if (scanf("%s", junk) <= 0) + if (scanf("%255s", junk) <= 0) printf("\nError: Cannot scan!\n"); } else if (choice && choice <= num_ports) break;