Segment fault in datastruct/hash.c
Hi all,
Found by Anders Johansson <[email protected]>, vgscan may
segment in datastruct/hash.c atmemcmp(key, (*c)->key, len). It happens because the (*c)->key is much shorter than the key, and the
memory area following (*c)->key is unaccessable at the time.
(gdb) p (*c)->key
$1 = 0x80229fb4 "/dev/disk/by-id/ccw-LXD332"
(gdb) x/80cb 0x80229fb40x80229fb4: 47 '/' 100 'd' 101 'e' 118 'v' 47 '/' 100 'd' 105 'i' 115 's'0x80229fbc: 107 'k' 47 '/' 98 'b' 121 'y' 45 '-' 105 'i' 100 'd' 47 '/'0x80229fc4: 99 'c' 99 'c' 119 'w' 45 '-' 76 'L' 88 'X' 68 'D' 51 '3'0x80229fcc: 51 '3' 50 '2' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0'0x80229fd4: 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0'0x80229fdc: 0 '\0' 0 '\0' 0 '\0' 49 '1' 0 '\0' 0 '\0' 0 '\0' 0 '\0'0x80229fe4: 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0'0x80229fec: 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0'0x80229ff4: 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0' 0 '\0'0x80229ffc: 0 '\0' 0 '\0' 0 '\0' 0 '\0' Cannot access memory at
address 0x8022a000
I generate a patch against the latest git tree. Please consider it
for inclusion.
Thanks.
libdm/datastruct/hash.c +5 -1
@@ -143,9 +143,13 @@ static struct dm_hash_node **_find(struct dm_hash_table *t, const char *key,unsigned h =_hash (key, len) & (t->num_slots -1 );struct dm_hash_node **c; -for (c = &t->slots[h]; *c; c = &((*c)->next)) +for (c = &t->slots[h]; *c; c = &((*c)->next)) { +if ((*c)->keylen != len) + continue +if (!memcmp (key, (*c)->key, len))break ; + }return c; }
Quoted 2 lines · Xinwei Hu
I generate a patch against the latest git tree. Please consider it
for inclusion.
Applied.
libdm/datastruct/hash.c static struct dm_hash_node **_find(struct dm_hash_table *t, const char *key, · line 145
Quoted 6 lines
libdm/datastruct/hash.c +2
-0@@ -143,9 +143,13 @@ static struct dm_hash_node **_find(struct dm_hash_table *t, const char *key, +if ((*c)->keylen != len) +continue
^
(Did you try the patch?)
Alasdair
2009/11/3 Alasdair G Kergon <[email protected]>:
Quoted 6 lines · Xinwei Hu
Quoted 2 lines
? I generate a patch against the latest git tree. Please consider it for inclusion.
Applied.
Quoted 7 lines
libdm/datastruct/hash.c static struct dm_hash_node **_find(struct dm_hash_table *t, const char *key, · line 145
Quoted 6 lines
libdm/datastruct/hash.c +2
-0@@ -143,9 +143,13 @@ static struct dm_hash_node **_find(struct dm_hash_table *t, const char *key, + ? ? ? ? ? ? if ((*c)->keylen != len) + ? ? ? ? ? ? ? ? ? ? continue? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?^
Sorry about that.
I copied tested patch into git manually at that time. Thought it's too simple to make a mistake, but I'm wrong -_-!!
Quoted 2 lines
(Did you try the patch?)
Yes, the original patch is tested and worked.
Quoted 3 lines
Alasdair