[OpenWrt-Devel] [PATCH] [libubox][v3] b64: add base64 support

Luka Perkov luka at openwrt.org
Tue Apr 14 12:24:48 EDT 2015


On Tue, Apr 14, 2015 at 06:00:32PM +0200, Felix Fietkau wrote:
> >> +	if (data[len - 1] == '=')
> >> +		ret--;
> >> +
> >> +	if (data[len - 2] == '=')
> >> +		ret--;
> > 
> > the 2 if clauses look redundant and i guess you could solve it with a loop

Ok. I'll fix it.

> I'd prefer not passing in the input buffer here at all - a tiny
> overestimation of the decode size doesn't hurt.

I don't think that is a good idea since we do not have NULL terminating
output buffer in b64decode(). If you really want a function without
input buffer we can make another one called:

static inline int b64_decode_size_approx(size_t len);

The overestimation is likely going to cause problems in cases like this:

buf = malloc(b64_decode_size(data, data_len));
if (!buf)
	return -1

buf_len = b64decode(rbuf, data, data_len);
if (!buf_len)
	return -1

write(fd, buf, buf_len);

In this case end of buf could be foobared and because of that extra
bytes could be written.

openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list