udev: ensure there is space for trailing NUL before calling sprintf
sprintf will write 5 characters, as it adds a trailing NUL byte.
Reported on yeswehack.com as:
YWH-PGM9780-62
Follow-up for 8cfcf9980a
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "device-nodes.h"
|
||||
#include "path-util.h"
|
||||
#include "stdio-util.h"
|
||||
#include "string-util.h"
|
||||
#include "utf8.h"
|
||||
|
||||
@@ -38,10 +39,10 @@ int encode_devnode_name(const char *str, char *str_enc, size_t len) {
|
||||
|
||||
} else if (str[i] == '\\' || !allow_listed_char_for_devnode(str[i], NULL)) {
|
||||
|
||||
if (len-j < 4)
|
||||
if (len-j < 5)
|
||||
return -EINVAL;
|
||||
|
||||
sprintf(&str_enc[j], "\\x%02x", (unsigned char) str[i]);
|
||||
assert_se(snprintf_ok(&str_enc[j], 5, "\\x%02x", (unsigned char) str[i]));
|
||||
j += 4;
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user