Commit Diff
Commit:
21fc67ae053c5b9471bbf16e990cfccdefa9c029
From:
Omar Polo <op@omarpolo.com>
Date:
Mon Dec 26 15:26:29 2022 UTC
Message
iri: use a temp buffer for %enc in iri_setquery
commit - 9987c6fb4f2e1754d290359f08988d29304f9d19
commit + 21fc67ae053c5b9471bbf16e990cfccdefa9c029
blob - 020fc8abf53f9480d4f3e55f9837b4534e801cc9
blob + 58725bc8b3d1797aa8a893c022b93919274f92c4
--- iri.c
+++ iri.c
@@ -711,7 +711,7 @@ iri_setquery(struct iri *iri, const char *p)
{
ptrdiff_t bufsize;
int r;
- char *buf, *q;
+ char *buf, *q, tmp[4];
buf = q = iri->iri_query;
bufsize = sizeof(iri->iri_query);
@@ -720,12 +720,15 @@ iri_setquery(struct iri *iri, const char *p)
*p == '/' || *p == '?')
*q++ = *p++;
else {
- if (q - buf >= bufsize - 4)
+ if (q - buf >= bufsize - 3)
goto err;
- r = snprintf(q, 4, "%%%02X", (int)*p);
- if (r < 0 || r > 4)
+ r = snprintf(tmp, sizeof(tmp), "%%%02X", (int)*p);
+ if (r < 0 || (size_t)r > sizeof(tmp))
return (-1);
- p++, q += 3;
+ *q++ = tmp[0];
+ *q++ = tmp[1];
+ *q++ = tmp[2];
+ p++;
}
}
if ((*p == '\0') && (q - buf < bufsize)) {
Omar Polo