Increment by three, not one, after successfully decoding a character.

Add a boundary check.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@858 185d5e19-27fe-0310-9dcf-9bff6b9f3609
This commit is contained in:
Dag-Erling Smørgrav 2015-03-19 00:07:19 +00:00
parent a1f83b0b30
commit 737e1bef50
1 changed files with 2 additions and 1 deletions

View File

@ -58,12 +58,13 @@ oath_uri_decode(const char *in, size_t ilen, char *out, size_t olen)
if (ilen == 0)
ilen = strlen(in);
for (ipos = opos = 0; ipos < ilen && in[ipos] != '\0'; ++ipos, ++opos) {
if (in[ipos] == '%' &&
if (in[ipos] == '%' && ipos + 2 < ilen &&
is_xdigit(in[ipos + 1]) && is_xdigit(in[ipos + 2])) {
if (out != NULL && opos < olen - 1)
out[opos] = unhex(in[ipos + 1]) * 16 +
unhex(in[ipos + 2]);
ilen += 2;
ipos += 2;
} else {
if (out != NULL && opos < olen - 1)
out[opos] = in[ipos];