From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 30F40A0093; Tue, 19 May 2020 11:17:40 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F3EC71D17E; Tue, 19 May 2020 11:17:38 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id E152E1D17A for ; Tue, 19 May 2020 11:17:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589879857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=T4CFsAYP3Y/MQeQRcLBebroBCVIFMpsqrqmWRaMjI/s=; b=IriBWJkGqlVQui6ZRqdV73GDq3q5RH8luDTivJi/ijrLmqshZV4tVbUPlppIsAq7KJB5Nz 77VJDv51ZRykrAwKZ0d4RxWInUnfV7A1yqezkm0haSISbXIV2vQhrtakvrlPk10SHFCfqz cXrbEkUUnl9O5x7UvMlwORgc6kuoYW8= Received: from mail-vk1-f197.google.com (mail-vk1-f197.google.com [209.85.221.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-344-dNscrmngO7mbFtRgmiGW7A-1; Tue, 19 May 2020 05:17:35 -0400 X-MC-Unique: dNscrmngO7mbFtRgmiGW7A-1 Received: by mail-vk1-f197.google.com with SMTP id k64so3072735vkk.4 for ; Tue, 19 May 2020 02:17:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=T4CFsAYP3Y/MQeQRcLBebroBCVIFMpsqrqmWRaMjI/s=; b=E2L5cdVpgWb2mHZ+i6P9bXF4DqJMbC+MOlRaYi4nHNnjLZTZ36kS3oonokTmX3bbB3 ngMO4660vAwHUyeFWtQrR189RiQNxEqBDPYjibSHtd14WYOtRxDpZcU+NVyB8vpewbWg Ih3826svqN+aGjZhdQRG/t1OIBcaMKfK/wYcUqfoXfth3wnPBMo54d4QTy37j/gaipmF kX9WdKwx8HLVNgi9OKn3+jUcJ+oypIjgslCy3zSyX1B9fgBuNSyFmCtNHAfP4Yc4P6Go GapNfSu/W8ejIfw4kg2/fXfpYzmUdDFN+BWzDffseTCUYZOo8w7+huTxyEAejDmNB3uk ga5Q== X-Gm-Message-State: AOAM531vhC/5K4Vk48B6/3sjOdGc8oFzIBgZ20zW3Hg2XJV178WX24pi R1S+RF3XjFNtbw4qhxP3+HW5fVRsuaN/oKe1Hj/PaTNpoTqsDI/VTaGdgyeR/+WqbnkXlqDR5ho 4TA6bVbcqpqiPvHBxqR4= X-Received: by 2002:a1f:8fd1:: with SMTP id r200mr11300013vkd.56.1589879855204; Tue, 19 May 2020 02:17:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxP7q1KeQqaFFluXTzYBNeXDXsd1HgemY4q2hjtyUfwK/ml28eOpuCO3CloJbQScxkpuPWfA3qPNs+Vo0pPSNc= X-Received: by 2002:a1f:8fd1:: with SMTP id r200mr11299999vkd.56.1589879854988; Tue, 19 May 2020 02:17:34 -0700 (PDT) MIME-Version: 1.0 References: <20200513104751.46466-1-grive@u256.net> <20200513104751.46466-2-grive@u256.net> In-Reply-To: <20200513104751.46466-2-grive@u256.net> From: David Marchand Date: Tue, 19 May 2020 11:17:24 +0200 Message-ID: To: Gaetan Rivet Cc: dev , dpdk stable , Luca Boccassi , Kevin Traynor X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH v1 1/2] pci: fix allowing underflow when parsing PCI id X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Wed, May 13, 2020 at 12:48 PM Gaetan Rivet wrote: > > The function strtoul will not return ERANGE if the input is negative, as > one might expect. > > 0000:-FFFFFFFFFFFFFFFB:00.0 > > is not a better way to write 0000:05:00.0. > To simplify checking for '-', forbid using spaces before the field value. > > 0000: 00: 2c.0 > > Should not be accepted. > > Fixes: af75078fece3 ("first public release") > Cc: stable@dpdk.org Not sure about backporting this one, will let stable maintainers reconsider this. > Signed-off-by: Gaetan Rivet Acked-by: Darek Stojaczyk > --- > lib/librte_pci/rte_pci.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/lib/librte_pci/rte_pci.c b/lib/librte_pci/rte_pci.c > index d1ab6b414..e4ecdc32f 100644 > --- a/lib/librte_pci/rte_pci.c > +++ b/lib/librte_pci/rte_pci.c > @@ -35,6 +35,12 @@ get_u8_pciaddr_field(const char *in, void *_u8, char dlm) > if (*in == '\0') > return NULL; > > + /* PCI field starting with spaces is forbidden. > + * Negative wrap-around is not reported as an error by strtoul. > + */ > + if (*in == ' ' || *in == '-') > + return NULL; > + > errno = 0; > val = strtoul(in, &end, 16); > if (errno != 0 || end[0] != dlm || val > UINT8_MAX) { > @@ -70,6 +76,12 @@ pci_dbdf_parse(const char *input, struct rte_pci_addr *dev_addr) > unsigned long val; > char *end; > > + /* PCI id starting with spaces is forbidden. > + * Negative wrap-around is not reported as an error by strtoul. > + */ > + if (*in == ' ' || *in == '-') > + return EINVAL; Should be -EINVAL, fixed. > + > errno = 0; > val = strtoul(in, &end, 16); > if (errno != 0 || end[0] != ':' || val > UINT16_MAX) > -- > 2.26.2 > Applied, thanks. -- David Marchand