- Fixed issues with mismatching Content-Length in replies causing extra bytes to spill over into the next message

This commit is contained in:
Olof hagsand 2021-05-06 14:34:31 +02:00
parent 6605ab8ce7
commit 866d8d1d0a

View file

@ -902,14 +902,14 @@ send_badrequest(clicon_handle h,
cprintf(cb, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n"); cprintf(cb, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n");
if (body){ if (body){
cprintf(cb, "Content-Type: %s\r\n", media); cprintf(cb, "Content-Type: %s\r\n", media);
cprintf(cb, "Content-Length: %lu\r\n", strlen(body)+2); cprintf(cb, "Content-Length: %lu\r\n", strlen(body));
} }
else else
cprintf(cb, "Content-Length: 0\r\n"); cprintf(cb, "Content-Length: 0\r\n");
cprintf(cb, "\r\n"); cprintf(cb, "\r\n");
if (body) if (body)
cprintf(cb, "%s\r\n", body); cprintf(cb, "%s\r\n", body);
if (buf_write(cbuf_get(cb), cbuf_len(cb)+1, s, ssl) < 0) if (buf_write(cbuf_get(cb), cbuf_len(cb), s, ssl) < 0)
goto done; goto done;
retval = 0; retval = 0;
done: done:
@ -1021,7 +1021,7 @@ restconf_connection(int s,
} }
} }
} }
if (buf_write(cbuf_get(rc->rc_outp_buf), cbuf_len(rc->rc_outp_buf)+1, conn->sock, conn->ssl) < 0) if (buf_write(cbuf_get(rc->rc_outp_buf), cbuf_len(rc->rc_outp_buf), conn->sock, conn->ssl) < 0)
goto done; goto done;
cvec_reset(rc->rc_outp_hdrs); /* Can be done in native_send_reply */ cvec_reset(rc->rc_outp_hdrs); /* Can be done in native_send_reply */
cbuf_reset(rc->rc_outp_buf); cbuf_reset(rc->rc_outp_buf);