consolidate /sbin/hotplug call for pci and usb
Quoted 9 lines · David Brownell
Review
Quoted 7 lines
(quoted diff) +7
-0+ /* stuff we want to pass to /sbin/hotplug */ + envp[i++] = scratch; + scratch += sprintf (scratch, "PCI_CLASS=%04X", pdev->class) + 1; + + envp[i++] = scratch; + scratch += sprintf (scratch, "PCI_ID=%04X:%04X", + pdev->vendor, pdev->device) + 1;And so forth. Use "snprintf" and prevent overrunning those buffers...
Hmm? An %04X format is perfectly bounded.
-Andi
Quoted 12 lines · Andi Kleen
Quoted 9 lines · David Brownell
Review
Quoted 7 lines
(quoted diff) +7
-0+ /* stuff we want to pass to /sbin/hotplug */ + envp[i++] = scratch; + scratch += sprintf (scratch, "PCI_CLASS=%04X", pdev->class) + 1; + + envp[i++] = scratch; + scratch += sprintf (scratch, "PCI_ID=%04X:%04X", + pdev->vendor, pdev->device) + 1;And so forth. Use "snprintf" and prevent overrunning those buffers...
Quoted 1 line
Hmm? An %04X format is perfectly bounded.
Technically, it isn't bounded. The field will expand if the value exceeds 4 digits.
However, these values can't do that. At least not now.
But, as a good programming practice, snprintf should be used. Heck, PCI 3.0 might use 32-bit vendor and device values, instead of 8 bit. So, if nothing else, do it as insurance for the future.
Matt
Signature · 6 lines
Matthew Dharm Home: [email protected] Maintainer, Linux USB Mass Storage Driver It was a new hope. -- Dust Puppy User Friendly, 12/25/1998
Quoted 13 lines · Matthew Dharm
Quoted 12 lines · Andi Kleen
Quoted 9 lines · David Brownell
Review
Quoted 7 lines
(quoted diff) +7
-0+ /* stuff we want to pass to /sbin/hotplug */ + envp[i++] = scratch; + scratch += sprintf (scratch, "PCI_CLASS=%04X", pdev->class) + 1; + + envp[i++] = scratch; + scratch += sprintf (scratch, "PCI_ID=%04X:%04X", + pdev->vendor, pdev->device) + 1;And so forth. Use "snprintf" and prevent overrunning those buffers...
Quoted 4 lines
Quoted 1 line
Hmm? An %04X format is perfectly bounded.
Technically, it isn't bounded. The field will expand if the value exceeds 4 digits.
It is bounded to 8 characters on linux systems (where int is always 32bit)
-Andi
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ envp[i++] = scratch; + scratch += sprintf (scratch, "PCI_ID=%04X:%04X", + pdev->vendor, pdev->device) + 1;And so forth. Use "snprintf" and prevent overrunning those buffers...
Hmm? An %04X format is perfectly bounded.
Which was my thought when I originally wrote the code which has been widely cut'n'pasted. Safe enough at that moment, but it's now become dangerous to leave that around as a copy/paste coding example.
Those code fragments are now being used in contexts that aren't as controlled as the original: the code _using_ the buffer is no longer in charge of allocating it. There's no longer any way to guarantee that adding the next parameter to the environment isn't going to overrun the available space.
Except by using "snprintf" and tracking how much space is left.
Easy enough to do, and that's a habit that IMO _everyone_ should be getting into whenever they program in languages that permit such buffer overflows.
Quoted 8 lines
Technically, it isn't bounded. The field will expand if the value exceeds 4 digits.
However, these values can't do that. At least not now.
But, as a good programming practice, snprintf should be used. Heck, PCI 3.0 might use 32-bit vendor and device values, instead of 8 bit. So, if nothing else, do it as insurance for the future.
And to help ensure that as people continue to copy/paste code from the core hotpluggable systems, they won't break things when they add the parameters needed to set up their new subsystem or class, using the /sbin/hotplug mechanism.
- Dave