-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src/libudev/conf-files.c: fix bug of using basename #198
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.