pci: a comment and a minor fix
cover pci: a comment and a minor fix
Add a clarifying comment and fix the PCI addr parser behavior for some edge-case.
Gaetan Rivet (2):
pci: fix allowing underflow when parsing PCI id
pci: explain how empty strings are rejected in DBDF
lib/librte_pci/rte_pci.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Signature · 1 line
2.26.2
PATCH 1/2 pci: fix allowing underflow when parsing PCI id
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.
--- lib/librte_pci/rte_pci.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
lib/librte_pci/rte_pci.c +12 -0
@@ -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 ; + errno =0 ; val =strtoul (in, &end,16 );if (errno !=0 || end[0 ] !=':' || val >UINT16_MAX )
Signature · 1 line
2.26.2
Re: [dpdk-dev] [PATCH v1 1/2] pci: fix allowing underflow when parsing PCI id
Quoted 16 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Gaetan Rivet
Sent: Wednesday, May 13, 2020 12:48 PM
To: [email protected]
Cc: [email protected]
Subject: [dpdk-dev] [PATCH v1 1/2] pci: fix allowing underflow when parsing PCI idThe function strtoul will not return ERANGE if the input is negative, as one might expect.
0000:-FFFFFFFFFFFFFFFB:00.0is not a better way to write 0000:05:00.0.
To simplify checking for '-', forbid using spaces before the field value.
Quoted 8 lines
0000: 00: 2c.0Should not be accepted.
Fixes af75078fece3 ("first public release")Signed-off-by Gaetan Rivet <[email protected]>---
Re: [dpdk-dev] [PATCH v1 1/2] pci: fix allowing underflow when parsing PCI id
In reply to Gaetan RivetQuoted 9 lines · Gaetan Rivet
The function strtoul will not return ERANGE if the input is negative, as one might expect.
0000:-FFFFFFFFFFFFFFFB:00.0is not a better way to write 0000:05:00.0.
To simplify checking for '-', forbid using spaces before the field value.
Quoted 6 lines
0000: 00: 2c.0Should not be accepted.
Fixes af75078fece3 ("first public release")
Not sure about backporting this one, will let stable maintainers reconsider this.
Quoted 1 line
Signed-off-by Gaetan Rivet <[email protected]>
Quoted 22 lines
--- lib/librte_pci/rte_pci.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)lib/librte_pci/rte_pci.c +6
-0@@ -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 ) {
lib/librte_pci/rte_pci.c pci_dbdf_parse(const char *input, struct rte_pci_addr *dev_addr) · line 83
Quoted 8 lines
lib/librte_pci/rte_pci.c +5
-0@@ -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.
Quoted 7 lines
lib/librte_pci/rte_pci.c +1
-1+ errno =0 ; val =strtoul (in, &end,16 );if (errno !=0 || end[0 ] !=':' || val >UINT16_MAX ) --2.26.2
Applied, thanks.
Signature · 1 line
David Marchand
PATCH 2/2 pci: explain how empty strings are rejected in DBDF
In reply to Gaetan RivetEmpty strings are forbidden as input to rte_pci_addr_parse(). It is explicitly enforced in BDF parsing as parsing the bus field will immediately fail. The related check is commented.
It is implicitly enforced in DBDF parsing, as the domain would be parsed to 0 without error, but the check end[0] != ':' afterward will return -EINVAL.
Enforcing consistency between parsers by reading the code is not helped by this property being implicit. Add a comment to explain.
--- lib/librte_pci/rte_pci.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/librte_pci/rte_pci.c +4 -0
@@ -84,6 +84,10 @@ pci_dbdf_parse(const char *input, struct rte_pci_addr *dev_addr) errno =0 ; val =strtoul (in, &end,16 ); +/* Empty string is not an error for strtoul, but the check +* end[0] != ':' +* will detect the issue. +*/ if (errno !=0 || end[0 ] !=':' || val >UINT16_MAX )return -EINVAL ; dev_addr->domain = (uint16_t )val;
Signature · 1 line
2.26.2
Re: [dpdk-dev] [PATCH v1 2/2] pci: explain how empty strings are rejected in DBDF
Quoted 15 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Gaetan Rivet
Sent: Wednesday, May 13, 2020 12:48 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v1 2/2] pci: explain how empty strings are rejected in DBDFEmpty strings are forbidden as input to
rte_pci_addr_parse(). It is explicitly enforced in BDF parsing as parsing the bus field will immediately fail. The related check is commented.It is implicitly enforced in DBDF parsing, as the domain would be parsed to 0 without error, but the check
end[0] != ':'afterward will return-EINVAL.
Quoted 5 lines
Enforcing consistency between parsers by reading the code is not helped by this property being implicit. Add a comment to explain.
Signed-off-by Gaetan Rivet <[email protected]>---
Re: [dpdk-dev] [PATCH v1 2/2] pci: explain how empty strings are rejected in DBDF
In reply to Gaetan RivetQuoted 5 lines · Gaetan Rivet
Empty strings are forbidden as input to
rte_pci_addr_parse(). It is explicitly enforced in BDF parsing as parsing the bus field will immediately fail. The related check is commented.
Quoted 8 lines
It is implicitly enforced in DBDF parsing, as the domain would be parsed to 0 without error, but the check
end[0] != ':'afterward will return-EINVAL.Enforcing consistency between parsers by reading the code is not helped by this property being implicit. Add a comment to explain.
Signed-off-by Gaetan Rivet <[email protected]>
Applied, thanks.
Signature · 1 line
David Marchand