From patchwork Wed Dec 22 19:47:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 428401 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBMJiS2X000372 for ; Wed, 22 Dec 2010 19:44:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751582Ab0LVTo1 (ORCPT ); Wed, 22 Dec 2010 14:44:27 -0500 Received: from nspiron-2.llnl.gov ([128.115.41.82]:41981 "EHLO nspiron-2.llnl.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751394Ab0LVTo1 (ORCPT ); Wed, 22 Dec 2010 14:44:27 -0500 X-Attachments: None Received: from mail-1.llnl.gov ([128.115.41.180]) by nspiron-2.llnl.gov with ESMTP; 22 Dec 2010 11:44:26 -0800 Received: from trebuchet.chaos (eris.llnl.gov [134.9.2.84]) by mail-1.llnl.gov (8.13.1/8.12.3/LLNL evision: 1.7 $) with SMTP id oBMJhZCd030438; Wed, 22 Dec 2010 11:43:35 -0800 Date: Wed, 22 Dec 2010 11:47:07 -0800 From: Ira Weiny To: Jay Fenlason Cc: Sasha Khapyorsky , "linux-rdma@vger.kernel.org" Subject: [PATCH] Further timeout paramater verification (Was: [PATCH] infiniband-diags: Verify timeout value specified to diagnostics) Message-Id: <20101222114707.c6ec051f.weiny2@llnl.gov> In-Reply-To: <20101220215735.GA4020@redhat.com> References: <20101220215735.GA4020@redhat.com> X-Mailer: Sylpheed 3.0.3 (GTK+ 2.10.4; x86_64-unknown-linux-gnu) Mime-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 22 Dec 2010 19:44:28 +0000 (UTC) diff --git a/infiniband-diags/src/ibdiag_common.c b/infiniband-diags/src/ibdiag_common.c index 8ccf2fc..8f5eec3 100644 --- a/infiniband-diags/src/ibdiag_common.c +++ b/infiniband-diags/src/ibdiag_common.c @@ -138,7 +138,8 @@ void ibdiag_show_usage() static int process_opt(int ch, char *optarg) { - int val; + char *endp; + long val; switch (ch) { case 'h': @@ -175,13 +176,16 @@ static int process_opt(int ch, char *optarg) ibd_dest_type = IB_DEST_GUID; break; case 't': - val = (int)strtol(optarg, NULL, 0); - if (val > 0) { - madrpc_set_timeout(val); - ibd_timeout = val; - } else + errno = 0; + val = strtol(optarg, &endp, 0); + if (errno || (endp && *endp != '\0') || val <= 0 || + val > INT_MAX) IBERROR("Invalid timeout \"%s\". Timeout requires a " - "positive integer value.", optarg); + "positive integer value < %d.", optarg, INT_MAX); + else { + madrpc_set_timeout((int)val); + ibd_timeout = (int)val; + } break; case 's': /* srcport is not required when resolving via IB_DEST_LID */