commit 34fd4f17068b408353bb6ae1df3eb4a58c259e25
parent cd386e712b7587740115c0fb0815a43052758ae2
Author: Quentin Rameau <quinq@fifth.space>
Date: Sat, 30 Jan 2021 19:44:16 +0100
Check that non-binary types end with ".\r\n"
Otherwise that means that the remote end send incomplete data.
Thanks to jhumphrey for spotting that!
Diffstat:
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/sacc.c b/sacc.c
@@ -599,20 +599,25 @@ cleanup:
static int
fetchitem(Item *item)
{
+ char *raw, *r;
int sock;
if ((sock = connectto(item->host, item->port)) < 0 ||
sendselector(sock, item->selector) < 0)
return 0;
- item->raw = getrawitem(sock);
+ raw = getrawitem(sock);
close(sock);
- if (item->raw && !*item->raw) {
+ if (raw == NULL || !*raw) {
diag("Empty response from server");
- clear(&item->raw);
+ clear(&raw);
+ } else if ((r = strrchr(raw, '.')) == NULL || strcmp(r, ".\r\n")) {
+ diag("Incomplete response from server");
+ } else {
+ *r = '\0';
}
- return (item->raw != NULL);
+ return ((item->raw = raw) != NULL);
}
static void