libc/net: Fix b64_pton() for some exact-sized buffer
authorAaron LI <aly@aaronly.me>
Sat, 30 Apr 2022 13:06:40 +0000 (21:06 +0800)
committerAaron LI <aly@aaronly.me>
Sun, 1 May 2022 15:23:03 +0000 (23:23 +0800)
commit3bf574a91d98898f33673d3b78fb3fe581c3c4e7
tree20d8da4d4cd642cb806657d1bf54262772be9a62
parentfe2da4c891f6d5ab555eac0ac3edc3241c50c1c5
libc/net: Fix b64_pton() for some exact-sized buffer

When decoding a base64 string with padding, b64_pton() can fail when the
output buffer is exactly the needed size.  For example, decoding the
following base64 string to buffer[32] would fail:

% dd if=/dev/random bs=32 count=1 | base64
FCiWkKuhdRq3tMmtAt9CpchTTYMlIW3U3gJsavDNxZI=

This commit fixes the above issue.

Reported-by: dczheng
Obtained-from: OpenBSD
See also: FreeBSD revision 275060, https://reviews.freebsd.org/D1218
lib/libc/net/base64.c