Skip to contentSkip to conversation

pci: fix parsing of address without function number

PATCH In review Thomas Monjalon 2 participants 3 messages Nov 11, 2018 – Nov 13, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: fix parsing of address without function number

If the last part of the PCI address (function number) is missing, the parsing was successful, assuming function 0.
The call to strtoul is not returning an error in such a case, so an explicit check is inserted before.

This bug has always been there in older parsing macros:
- GET_PCIADDR_FIELD
- GET_BLACKLIST_FIELD

Fixes af75078fece3 ("first public release")
---
 lib/librte_pci/rte_pci.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/librte_pci/rte_pci.c +4 -0
index 530738dbd..f400178bb 100644
@@ -30,6 +30,10 @@ get_u8_pciaddr_field(const char *in, void *_u8, char dlm)
 	uint8_t *u8 = _u8;
 	char *end;
 
+	/* empty string is an error though strtoul() returns 0 */
+	if (*in == '\0')
+		return NULL;
+
 	errno = 0;
 	val = strtoul(in, &end, 16);
 	if (errno != 0 || end[0] != dlm || val > UINT8_MAX) {
Signature · 1 line
2.19.0
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Thomas Monjalon

If the last part of the PCI address (function number) is missing, the parsing was successful, assuming function 0.
The call to strtoul is not returning an error in such a case, so an explicit check is inserted before.

This bug has always been there in older parsing macros:
- GET_PCIADDR_FIELD
- GET_BLACKLIST_FIELD

Returning 0, that's understandable, but errno not being set is rather lame from strtoul.

Quoted 5 lines
Fixes af75078fece3 ("first public release")
Quoted 22 lines
---
 lib/librte_pci/rte_pci.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/librte_pci/rte_pci.c +4 -0
index 530738dbd..f400178bb 100644
@@ -30,6 +30,10 @@ get_u8_pciaddr_field(const char *in, void *_u8, char dlm)
 	uint8_t *u8 = _u8;
 	char *end;
 
+	/* empty string is an error though strtoul() returns 0 */
+	if (*in == '\0')
+		return NULL;
+
 	errno = 0;
 	val = strtoul(in, &end, 16);
 	if (errno != 0 || end[0] != dlm || val > UINT8_MAX) {
Signature · 1 line
2.19.0
Signature · 2 lines
Gaëtan Rivet
6WIND
author Applied
#2 lore raw

12/11/2018 10:29, Gaëtan Rivet:

Quoted 14 lines · Thomas Monjalon
Quoted 9 lines

If the last part of the PCI address (function number) is missing, the parsing was successful, assuming function 0.
The call to strtoul is not returning an error in such a case, so an explicit check is inserted before.

This bug has always been there in older parsing macros:
- GET_PCIADDR_FIELD
- GET_BLACKLIST_FIELD

Returning 0, that's understandable, but errno not being set is rather lame from strtoul.

Quoted 6 lines
Quoted 5 lines
Fixes af75078fece3 ("first public release")

Applied