From patchwork Tue Jan 23 00:48:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 10179449 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 0A2AD60353 for ; Tue, 23 Jan 2018 00:48:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFC8A28571 for ; Tue, 23 Jan 2018 00:48:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4A392857E; Tue, 23 Jan 2018 00:48:12 +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=-6.9 required=2.0 tests=BAYES_00,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 8EAB528571 for ; Tue, 23 Jan 2018 00:48:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751318AbeAWAsM (ORCPT ); Mon, 22 Jan 2018 19:48:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36672 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751253AbeAWAsL (ORCPT ); Mon, 22 Jan 2018 19:48:11 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A5212C057EC3; Tue, 23 Jan 2018 00:48:11 +0000 (UTC) Received: from test1190.test.redhat.com (vpn2-54-18.bne.redhat.com [10.64.54.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DEC05D6A3; Tue, 23 Jan 2018 00:48:09 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Pavel Shilovsky Subject: [PATCH] cifscreds: check optind before accessing argv[optind] Date: Tue, 23 Jan 2018 11:48:01 +1100 Message-Id: <20180123004801.10182-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 23 Jan 2018 00:48:11 +0000 (UTC) Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Redhat bugzilla: 1278543 This fixes a segfault for some incorrect usage, for example cifscreds -u test Signed-off-by: Ronnie Sahlberg --- cifscreds.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cifscreds.c b/cifscreds.c index 5d84c3c..32f2ee4 100644 --- a/cifscreds.c +++ b/cifscreds.c @@ -487,6 +487,9 @@ int main(int argc, char **argv) } } + if (optind >= argc) + return usage(); + /* find the best fit command */ best = NULL; n = strnlen(argv[optind], MAX_COMMAND_SIZE);