lwip: wget: process legacy url with strncpy
PATCH 1/1 lwip: wget: process legacy url with strncpy
Commit 356011f ("lwip: fix code style issues") changed two strncpy calls to strlcpy calls in the function net/lwip/wget.c:parse_legacy_args, but this breaks the correct parsing of a legacy url. strlcpy expects the size of the destination buffer, not of the amount of bytes to be copied, and it will stop when the buffer ends or when a null is found, but here we want to copy a specific amount of bytes and there is no null at the end of that specific amount of bytes. The change is reverted here. Optionally, all the calls to strlcpy(,,n) could be changed to strlcpy(,,n+1).
--- net/lwip/wget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/lwip/wget.c +2 -2
@@ -180,7 +180,7 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem)if (rem < n)return -1 ; -strlcpy (p, server, n); +strncpy (p, server, n); p += n; rem -= n;if (rem <1 )
@@ -191,7 +191,7 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem) n =strlen (path);if (rem < n)return -1 ; -strlcpy (p, path, n); +strncpy (p, path, n); p += n; rem -= n;if (rem <1 )
Signature · 1 line
2.43.0
Quoted 29 lines · Adriano Cordova
Commit 356011f ("lwip: fix code style issues") changed two strncpy calls to strlcpy calls in the function net/lwip/wget.c:parse_legacy_args, but this breaks the correct parsing of a legacy url. strlcpy expects the size of the destination buffer, not of the amount of bytes to be copied, and it will stop when the buffer ends or when a null is found, but here we want to copy a specific amount of bytes and there is no null at the end of that specific amount of bytes. The change is reverted here. Optionally, all the calls to
strlcpy(,,n)could be changed tostrlcpy(,,n+1).Fixes 356011f ("lwip: fix code style issues")Signed-off-by Adriano Cordova <[email protected]>--- net/lwip/wget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/lwip/wget.c +1
-1@@ -180,7 +180,7 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem)if (rem < n)return -1 ; -strlcpy (p, server, n); +strncpy (p, server, n); p += n; rem -= n;if (rem <1 )
net/lwip/wget.c static int parse_legacy_arg(char *arg, char *nurl, size_t rem) · line 197
Quoted 8 lines
net/lwip/wget.c +1
-1@@ -191,7 +191,7 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem) n =strlen (path);if (rem < n)return -1 ; -strlcpy (p, path, n); +strncpy (p, path, n); p += n; rem -= n;if (rem <1 )
I already sent the same fix as [1].
[1] https://lists.denx.de/pipermail/u-boot/2024-November/573054.html
Thanks,
Signature · 1 line
Jerome
Ah ok, thanks for pointing it out. I think it is not in the next branch.
Il gio 28 nov 2024, 11:56 Jerome Forissier <[email protected]> ha scritto:
Quoted 59 lines · Adriano Cordova
Quoted 1 line
Commit 356011f ("lwip: fix code style issues") changed two strncpy
calls to
Quoted 1 line
strlcpy calls in the function net/lwip/wget.c:parse_legacy_args, but
this
Quoted 1 line
breaks the correct parsing of a legacy url. strlcpy expects the size
of the
Quoted 1 line
destination buffer, not of the amount of bytes to be copied, and it
will stop
Quoted 1 line
when the buffer ends or when a null is found, but here we want to
copy a
Quoted 1 line
specific amount of bytes and there is no null at the end of that
specific
Quoted 1 line
amount of bytes. The change is reverted here. Optionally, all the
calls to
net/lwip/wget.c static int parse_legacy_arg(char *arg, char *nurl,
Quoted 13 lines
strlcpy(,,n)could be changed tostrlcpy(,,n+1).Fixes 356011f ("lwip: fix code style issues")Signed-off-by Adriano Cordova <[email protected]>--- net/lwip/wget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/lwip/wget.c +0
-0@@ -180,7 +180,7 @@ static int parse_legacy_arg(char *arg, char *nurl,
size_trem)net/lwip/wget.c static int parse_legacy_arg(char *arg, char *nurl,
Quoted 9 lines
net/lwip/wget.c +1
-1if (rem < n)return -1 ; -strlcpy (p, server, n); +strncpy (p, server, n); p += n; rem -= n;if (rem <1 )@@ -191,7 +191,7 @@ static int parse_legacy_arg(char *arg, char *nurl,
size_trem)net/lwip/wget.c static int parse_legacy_arg(char *arg, char *nurl, size_t rem) · line 197
Quoted 8 lines
net/lwip/wget.c +1
-1n =strlen (path);if (rem < n)return -1 ; -strlcpy (p, path, n); +strncpy (p, path, n); p += n; rem -= n;if (rem <1 )I already sent the same fix as [1].
[1] https://lists.denx.de/pipermail/u-boot/2024-November/573054.html
Thanks,
--
Jerome