src/libudev/conf-files.c: fix bug of using basename#198
src/libudev/conf-files.c: fix bug of using basename#198bbonev merged 1 commit intoeudev-project:masterfrom
Conversation
bb232d7 to
7a4377b
Compare
|
|
Is it acceptable using custom basename_internal? |
|
src/shared/conf-files.c:145: string_hash_func calculates the hash based on the string value, not the pointer, so that part is safe But this one is not: Instead of looping over all path components, what about using |
|
Holding an implementation of a function is quite fine, though, as noted, strrchr might save on some code in there. |
|
While at it, maybe it is a good idea to also include this: It discards the |
|
@xfan1024 What about that: const char *eudev_basename(const char *filename) {
char *p=strrchr(filename,'/');
if (p)
return p+1;
return filename;
}Because this is used in more than one place, it would best to put it in |
Agree it. |
hashmap hold string's pointer not string's value. hashmap_put have 2 steps to check the key is exists, first calculate string's hash code, second strcmp all string in hashmap which have the same hash code, that equivalent to |
40912bc to
baa7e20
Compare
|
There is one more invocation - src/shared/util.c:1728 |
BASENAME(3) Linux Programmer's Manual say: > These functions may return pointers to statically allocated memory > which may be overwritten by subsequent calls. Using basename return value as key of hashmap is not safe, it may cause that hashmap_put always return -EEXIST if hash collision happen. Using basename return value as strcmp first and second parameters may always return 0. Signed-off-by: xiaofan <xiaofan@iscas.ac.cn>
Done |
bbonev
left a comment
There was a problem hiding this comment.
Thank you for your contribution to eudev!
BASENAME(3) Linux Programmer's Manual say:
Using basename return value as key of hashmap is not safe, it may
cause that hashmap_put always return -EEXIST if hash collision happen.
Using basename return value as strcmp first and second parameters may
always return 0.