Merge pull request #229 from vDorst/fix_login

Fix and refactor is_url_word_x()
This commit is contained in:
logicog
2026-05-18 18:30:28 +02:00
committed by GitHub
+44 -18
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;
i++;
j++;
} }
if (c[j] != ' ' && c[j] != '\t' && c[j] != ':' && c[j] != '?' && c[j] != '=' && c[j] != '\n' && c[j] != '\r' && c[j]) if (u == '%') {
return 0; bool again = true;
return 1; 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;
}
}
} }
@@ -441,6 +459,13 @@ void handle_post(void)
} }
} else if (is_word(request_path, "login")) { } else if (is_word(request_path, "login")) {
dbg_string("POST login\n"); dbg_string("POST login\n");
if (!content_type || !is_word(content_type, "application/x-www-form-urlencoded")) {
dbg_string("Bad request!\n");
send_bad_request();
return;
}
p += 8; // Read also over "pwd=" p += 8; // Read also over "pwd="
if (is_url_word_x(p, passwd)) { if (is_url_word_x(p, passwd)) {
dbg_string("Password accepted!\n"); dbg_string("Password accepted!\n");
@@ -453,6 +478,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;