Fix adb device ip parsing

The parser assumed that its input was a NUL-terminated string, but it
was not the case: it is just the raw output of "adb devices ip route".

In practice, it was harmless, since the output always ended with '\n'
(which was replaced by '\0' on truncation), but it was incorrect
nonetheless.

Always write a '\0' at the end of the buffer, and explicitly parse as a
NUL-terminated string. For that purpose, avoid the error-prone
sc_str_truncate() util function.
This commit is contained in:
Romain Vimont
2022-02-06 10:52:55 +01:00
parent 5b3ae2cb2f
commit 5d6bd8f9cd
4 changed files with 43 additions and 22 deletions

View File

@@ -8,9 +8,11 @@
/**
* Parse the ip from the output of `adb shell ip route`
*
* The parameter must be a NUL-terminated string.
*
* Warning: this function modifies the buffer for optimization purposes.
*/
char *
sc_adb_parse_device_ip_from_output(char *buf, size_t buf_len);
sc_adb_parse_device_ip_from_output(char *str);
#endif