Fix and refactor is_url_word_x().

With content_type = "application/x-www-form-urlencoded", "+" means space.
This case was not handled.

Also refactor the code to make a loop to process the hex digits.
This commit is contained in:
René van Dorst
2026-05-17 21:23:35 +02:00
parent 623247da4f
commit 4b40efafbb
+38 -19
View File
@@ -131,28 +131,46 @@ char is_word(__xdata uint8_t *c, __code uint8_t * __xdata d)
} }
char is_url_word_x(__xdata uint8_t *c, __xdata uint8_t *d) bool is_url_word_x(__xdata uint8_t *uri_str_p, __xdata uint8_t *src_str_p)
{ {
uint8_t i = 0, j = 0; uint8_t u, s;
while (d[i]) { while(1) {
if (c[j] == '%') { u = *uri_str_p++;
uint8_t v; s = *src_str_p++;
j++;
v = c[j] - '0' < 10 ? (c[j] - '0') << 4 : (c[j] - 'A' + 10) << 4; if (s == '\0') {
j++; if (u != '\0' && u != ' ' && u != '\t' && u != ':' && u != '?' && u != '=' && u != '\n' && u != '\r')
v += c[j] - '0' < 10 ? c[j] - '0' : c[j] - 'A' + 10; return false;
if (d[i] != v) return true;
return 0; }
} else if (d[i] != c[j])
return 0; if (u == '%') {
i++; bool again = true;
j++; u = 0;
while(1) {
// Swap instruction is fine for rotation
u = (u << 4) | (u >> 4);
uint8_t p = *uri_str_p++;
u |= p - '0' < 10 ? (p - '0') : (p - 'A' + 10);
// force `jbc`-instruction.
if (again) {
again = false;
} else {
break;
}
}
} else if (u == '+') {
u = ' ';
}
if (s != u) {
return false;
}
} }
if (c[j] != ' ' && c[j] != '\t' && c[j] != ':' && c[j] != '?' && c[j] != '=' && c[j] != '\n' && c[j] != '\r' && c[j])
return 0;
return 1;
} }
@@ -461,6 +479,7 @@ void handle_post(void)
outbuf[slen++] = session_id[i]; outbuf[slen++] = session_id[i];
slen += strtox(outbuf + slen, "; SameSite=Strict\r\n\r\n"); slen += strtox(outbuf + slen, "; SameSite=Strict\r\n\r\n");
} else { } else {
dbg_string("Password invalid!\n");
slen = strtox(outbuf, "HTTP/1.1 302 Found\r\nLocation: login.html\r\n\r\n"); slen = strtox(outbuf, "HTTP/1.1 302 Found\r\nLocation: login.html\r\n\r\n");
} }
return; return;