Re: PATCH 1/3: Fix buffer overflow and wrong behavior in url_encode
Mikael Magnusson <[email protected]>
| Newsgroups | gmane.comp.shells.zsh.devel |
|---|---|
| Message-ID | <CAHYJk3QMWe9mB3ebVf56sA1f9KkmwbDyajNrxOBGKTs6-NmaZg@mail.gmail.com> |
On Thu, May 7, 2026 at 11:35 AM Philippe Altherr <[email protected]> wrote: > > "const unsigned char *in" looks very weird to me. Wouldn't it be possible to cast "*in" in the call to sprintf: > > out += sprintf(out, "%%%02X", (unsigned char)*in); > > or maybe > > out += sprintf(out, "%%%02X", *in & 0xFF); It is indeed another possibility, which is why I asked. But if we do that, we'd also need to cast it for the isalnum() call. However, and I didn't notice this before, base64_encode already looks like this (surely mangled by gmail): static char* base64_encode(const char *src, size_t len) { static const char* base64_table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; const unsigned char *end = (unsigned char *)src + len; const unsigned char *in = (unsigned char *)src; So I think I'll just use that pattern. (I wasn't sure if the cast needed a const too, guess not). -- Mikael Magnusson