Fix bind local device#929
Conversation
|
New code does not store the NUL byte. What bug is this fixing? If you invoke |
|
If we set channel->local_dev_name to "eth0", sizeof(channel->local_dev_name) is 32, ares_strlen(channel->local_dev_name) is 4, the function calling of default_asetsockopt(sock, ARES_SOCKET_OPT_BIND_DEVICE, "ccmni0", 32, user_data) is not working as expected. It returns -1 after ares_str_isprint() check failed, doesn't run to setsockopt line.
|
|
manpage does say it needs to be a null-terminated string. That said, it doesn't say if the length provided needs to include the NUL character. That said, the logic here is definitely wrong: c-ares/src/lib/ares_set_socket_functions.c Line 291 in a8c0917 We should check that the buffer up to the first NUL byte (not to exceed the provided length) is printable. I think the change in this PR is also valid, however, especially if its been tested to work. But the function called should also be fixed to prevent regressions in the future. |
|
The old code writes exact amount (32) of bytes. The new code uses strlen without bounds-checking, writing an arbitrary amount of bytes to fixed-width array. There is also an issue of a buffer overflow. |
|
channel->local_dev_name is a buffer we provide during and copied into during ares_init_options, so its guaranteed to be a valid null-terminated string without overflow. |
Add a new function `ares_strnlen()` to fix the logic in default_asetsockopt(), see <c-ares#929 (comment)>.
Add a new function `ares_strnlen()` to fix the logic in default_asetsockopt(), see <#929 (comment)>. Authored-By: Nikolaos Chatzikonstantinou (@createyourpersonalaccount)
Add a new function `ares_strnlen()` to fix the logic in default_asetsockopt(), see <#929 (comment)>. Authored-By: Nikolaos Chatzikonstantinou (@createyourpersonalaccount)
Of course this change works for me(on an Android Arm platform) |
sizeof(channel->local_dev_name) will always be 32 and cause ares_str_isprint() check failed in default_asetsockopt() Fix By: @marcovsz
Add a new function `ares_strnlen()` to fix the logic in default_asetsockopt(), see <c-ares#929 (comment)>. Authored-By: Nikolaos Chatzikonstantinou (@createyourpersonalaccount)
sizeof(channel->local_dev_name) will always be 32 and cause ares_str_isprint() check failed in default_asetsockopt() Fix By: @marcovsz
…ator (c-ares#935) See c-ares#929 for discussion Signed-off-by: Brad House (@bradh352)
sizeof(channel->local_dev_name) will always be 32 and cause ares_str_isprint() check failed in default_asetsockopt()