From patchwork Mon Jul 23 23:45:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Chu X-Patchwork-Id: 1229191 X-Patchwork-Delegate: ira.weiny@intel.com Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 74FE5E0079 for ; Mon, 23 Jul 2012 23:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755093Ab2GWXpe (ORCPT ); Mon, 23 Jul 2012 19:45:34 -0400 Received: from nspiron-2.llnl.gov ([128.115.41.82]:64280 "EHLO nspiron-2.llnl.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755082Ab2GWXpd (ORCPT ); Mon, 23 Jul 2012 19:45:33 -0400 X-Attachments: Received: from auk59.llnl.gov (HELO [134.9.93.24]) ([134.9.93.24]) by nspiron-2.llnl.gov with ESMTP; 23 Jul 2012 16:45:33 -0700 Subject: [PATCH] infiniband-diags: Fix command line parsing bug in ibccconfig, ibccquery, saquery, and smpquery. From: Albert Chu To: linux-rdma@vger.kernel.org Date: Mon, 23 Jul 2012 16:45:33 -0700 Message-Id: <1343087133.18615.160.camel@auk59.llnl.gov> Mime-Version: 1.0 X-Mailer: Evolution 2.12.3 (2.12.3-19.el5) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Ensure user's inputted operation directly matches an operation name or operation alias. Do not base it on the length of the input, which can lead to conflicts with operation selection. Signed-off-by: Albert Chu --- src/ibccconfig.c | 5 ++--- src/ibccquery.c | 5 ++--- src/saquery.c | 5 ++--- src/smpquery.c | 5 ++--- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/ibccconfig.c b/src/ibccconfig.c index c81b7fa..a2572d0 100644 --- a/src/ibccconfig.c +++ b/src/ibccconfig.c @@ -561,10 +561,9 @@ static char *congestion_control_table(ib_portid_t * dest, char **argv, int argc) static op_fn_t *match_op(char *name) { const match_rec_t *r; - unsigned len = strlen(name); for (r = match_tbl; r->name; r++) - if (!strncasecmp(r->name, name, len) || - (r->alias && !strncasecmp(r->alias, name, len))) + if (!strcasecmp(r->name, name) || + (r->alias && !strcasecmp(r->alias, name))) return r->fn; return NULL; } diff --git a/src/ibccquery.c b/src/ibccquery.c index cf8b35a..5f9cf33 100644 --- a/src/ibccquery.c +++ b/src/ibccquery.c @@ -347,10 +347,9 @@ static char *timestamp_dump(ib_portid_t * dest, char **argv, int argc) static op_fn_t *match_op(char *name) { const match_rec_t *r; - unsigned len = strlen(name); for (r = match_tbl; r->name; r++) - if (!strncasecmp(r->name, name, len) || - (r->alias && !strncasecmp(r->alias, name, len))) + if (!strcasecmp(r->name, name) || + (r->alias && !strcasecmp(r->alias, name))) return r->fn; return NULL; } diff --git a/src/saquery.c b/src/saquery.c index e5fdb25..7c5f2cf 100644 --- a/src/saquery.c +++ b/src/saquery.c @@ -1327,11 +1327,10 @@ static const struct query_cmd query_cmds[] = { static const struct query_cmd *find_query(const char *name) { const struct query_cmd *q; - unsigned len = strlen(name); for (q = query_cmds; q->name; q++) - if (!strncasecmp(name, q->name, len) || - (q->alias && !strncasecmp(name, q->alias, len))) + if (!strcasecmp(name, q->name) || + (q->alias && !strcasecmp(name, q->alias))) return q; return NULL; diff --git a/src/smpquery.c b/src/smpquery.c index cecfa68..6468f23 100644 --- a/src/smpquery.c +++ b/src/smpquery.c @@ -401,10 +401,9 @@ static char *guid_info(ib_portid_t * dest, char **argv, int argc) static op_fn_t *match_op(char *name) { const match_rec_t *r; - unsigned len = strlen(name); for (r = match_tbl; r->name; r++) - if (!strncasecmp(r->name, name, len) || - (r->alias && !strncasecmp(r->alias, name, len))) + if (!strcasecmp(r->name, name) || + (r->alias && !strcasecmp(r->alias, name))) return r->fn; return NULL; }