udev-util: bound leading whitespace skip in udev_replace_whitespace
The function documents that at most 'len' bytes are read from 'str', but the leading whitespace skip used strspn(), which is bounded only by a non-whitespace byte or a NUL. ata_id passes the space padded, non-NUL-terminated ATA IDENTIFY fields, so an all-blank model reads past the buffer. Use strnspn() to cap the skip to 'len'.
This commit is contained in:
@@ -315,7 +315,9 @@ size_t udev_replace_whitespace(const char *str, char *to, size_t len) {
|
||||
*
|
||||
* Note that only 'len' characters are read from 'str'. */
|
||||
|
||||
i = strspn(str, WHITESPACE);
|
||||
/* Skip leading whitespace, but read at most 'len' bytes: 'str' is not necessarily NUL
|
||||
* terminated within 'len' (e.g. the space padded ATA IDENTIFY fields ata_id passes in). */
|
||||
i = strnspn(str, WHITESPACE, len);
|
||||
|
||||
for (j = 0; j < len && i < len && str[i] != '\0'; i++) {
|
||||
if (isspace(str[i])) {
|
||||
|
||||
Reference in New Issue
Block a user