[klibc] [PATCH] Fix the inet_pton implementation

Ben Hutchings ben at decadent.org.uk
Thu Mar 21 15:35:23 PDT 2024


On Mon, 2024-02-26 at 17:24 -0800, Donny Xia wrote:
> The function inet_pton should read from src but it actually reads
> from dst.
> 

Applied, thank you!

Since this function obviously hadn't been tested before, I've also
added a test program and fixed some other more minor bugs.

Ben.

> Signed-off-by: Donny Xia <xiadong.main at gmail.com>
> ---
>  usr/klibc/inet/inet_pton.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/usr/klibc/inet/inet_pton.c b/usr/klibc/inet/inet_pton.c
> index 19fe16e0..2df6b677 100644
> --- a/usr/klibc/inet/inet_pton.c
> +++ b/usr/klibc/inet/inet_pton.c
> @@ -38,7 +38,7 @@ int inet_pton(int af, const char *src, void *dst)
>  
>  			/* A double colon will increment colons by 2,
>  			   dcolons by 1 */
> -			for (p = dst; *p; p++) {
> +			for (p = src; *p; p++) {
>  				if (p[0] == ':') {
>  					colons++;
>  					if (p[1] == ':')
> @@ -54,7 +54,7 @@ int inet_pton(int af, const char *src, void *dst)
>  			memset(d, 0, sizeof(struct in6_addr));
>  
>  			i = 0;
> -			for (p = dst; *p; p++) {
> +			for (p = src; *p; p++) {
>  				if (*p == ':') {
>  					if (p[1] == ':') {
>  						i += (8 - colons);

-- 
Ben Hutchings
Humour is the best antidote to reality.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zytor.com/archives/klibc/attachments/20240321/aff10869/attachment.sig>


More information about the klibc mailing list