From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dennis Dalessandro Subject: [PATCH for-next 02/11] IB/hfi1: Check return value of strchr before using it Date: Mon, 18 Dec 2017 19:56:23 -0800 Message-ID: <20171219035621.2126.23093.stgit@scvm10.sc.intel.com> References: <20171219034753.2126.78386.stgit@scvm10.sc.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20171219034753.2126.78386.stgit-9QXIwq+3FY+1XWohqUldA0EOCMrvLtNR@public.gmane.org> Sender: linux-rdma-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: jgg-uk2M96/98Pc@public.gmane.org, dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, "Michael J. Ruhl" List-Id: linux-rdma@vger.kernel.org The call to strchr in our counter initialization does not check the return value before attempting to use the pointer. In theory this should not happen given the way the code is structured but do the smart thing and check the value anyway to harden the code. Reviewed-by: Michael J. Ruhl Signed-off-by: Dennis Dalessandro --- drivers/infiniband/hw/hfi1/verbs.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/verbs.c b/drivers/infiniband/hw/hfi1/verbs.c index 6d27c85..2487190 100644 --- a/drivers/infiniband/hw/hfi1/verbs.c +++ b/drivers/infiniband/hw/hfi1/verbs.c @@ -1733,6 +1733,12 @@ static int init_cntr_names(const char *names_in, for (i = 0; i < n; i++) { q[i] = p; p = strchr(p, '\n'); + if (!p) { + *num_cntrs = 0; + *cntr_names = NULL; + kfree(names_out); + return -EINVAL; + } *p++ = '\0'; } -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html