Merge pull request #19820 from yuwata/udev-node-fix-hashed-path

udev: fix conflict of hashed string
This commit is contained in:
Lennart Poettering
2021-06-07 17:19:38 +02:00
committed by GitHub
2 changed files with 16 additions and 5 deletions
+12
View File
@@ -33,6 +33,18 @@ static void test_udev_node_escape_path(void) {
strcpy(b + sizeof(b) - 12, "N3YhcCqFeID");
test_udev_node_escape_path_one(a, b);
strcpy(a + sizeof(a) - 12 - 9, "N3YhcCqFeID");
strcpy(b + sizeof(b) - 12, "L1oK9iKWdmi");
test_udev_node_escape_path_one(a, b);
strcpy(a + sizeof(a) - 12 - 9, "a");
strcpy(b + sizeof(b) - 12, "A7oaHBRuuZq");
test_udev_node_escape_path_one(a, b);
a[sizeof(a) - 12 - 9] = '\0';
b[sizeof(a) - 12] = '\0';
test_udev_node_escape_path_one(a, b);
}
int main(int argc, char *argv[]) {
+4 -5
View File
@@ -219,20 +219,21 @@ size_t udev_node_escape_path(const char *src, char *dest, size_t size) {
assert(src);
assert(dest);
assert(size >= 12);
for (i = 0, j = 0; src[i] != '\0'; i++) {
if (src[i] == '/') {
if (j+4 >= size)
if (j+4 >= size - 12 + 1)
goto toolong;
memcpy(&dest[j], "\\x2f", 4);
j += 4;
} else if (src[i] == '\\') {
if (j+4 >= size)
if (j+4 >= size - 12 + 1)
goto toolong;
memcpy(&dest[j], "\\x5c", 4);
j += 4;
} else {
if (j+1 >= size)
if (j+1 >= size - 12 + 1)
goto toolong;
dest[j] = src[i];
j++;
@@ -247,8 +248,6 @@ toolong:
h = siphash24_string(src, UDEV_NODE_HASH_KEY.bytes);
assert(size >= 12);
for (unsigned k = 0; k <= 10; k++)
dest[size - k - 2] = urlsafe_base64char((h >> (k * 6)) & 63);