Accept commands that aren't terminated in CRLF

Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar>
Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
Santiago Lo Coco 2022-06-21 20:58:38 -03:00
parent 0d67b3a33e
commit ab9acecea1
1 changed files with 11 additions and 3 deletions

View File

@ -1107,7 +1107,7 @@ static unsigned copy_r(struct selector_key * key) {
if (d->parser_user != NULL && pwd_dissector_active) { if (d->parser_user != NULL && pwd_dissector_active) {
struct parser_event * st = NULL; struct parser_event * st = NULL;
for (int i = 0, k = 0; i < n; i++) { for (int i = 0, k = 0; i < n && i <= USER_MAX_SIZE; i++) {
if (st != NULL && st->type == STRING_CMP_NEQ) { if (st != NULL && st->type == STRING_CMP_NEQ) {
parser_reset(d->parser_user); parser_reset(d->parser_user);
parser_reset(d->parser_pass); parser_reset(d->parser_pass);
@ -1122,14 +1122,22 @@ static unsigned copy_r(struct selector_key * key) {
d->user[k++] = *(ptr + i); d->user[k++] = *(ptr + i);
if (*(ptr + i) == '\n') { if (*(ptr + i) == '\n') {
d->user_done = true; d->user_done = true;
if (d->user[k - 2] == '\r') {
d->user[k - 2] = 0; d->user[k - 2] = 0;
} else {
d->user[k - 1] = 0;
}
k = 0; k = 0;
} }
} }
else if (!d->pass_done && st->type == STRING_CMP_EQ) { else if (!d->pass_done && st->type == STRING_CMP_EQ) {
if (*(ptr + i) == '\n') { if (*(ptr + i) == '\n') {
d->pass_done = true; d->pass_done = true;
if (d->pass[k - 1] == '\r') {
d->pass[k - 1] = 0; d->pass[k - 1] = 0;
} else {
d->pass[k] = 0;
}
log_request_password((const struct sockaddr *) &ATTACHMENT(key)->origin_addr, ATTACHMENT(key)->username, d->user, d->pass); log_request_password((const struct sockaddr *) &ATTACHMENT(key)->origin_addr, ATTACHMENT(key)->username, d->user, d->pass);
d->user_done = false; d->user_done = false;
d->pass_done = false; d->pass_done = false;