tCheck that non-binary types end with ".\r\n" - sacc - [fork] customized build … | |
git clone git://src.adamsgaard.dk/sacc | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 555e4735b22a5980dc39bda9da4a74d277d2f9f0 | |
parent dddcf903ff9fd4781226e02d8aed1221c13940c7 | |
Author: Quentin Rameau <[email protected]> | |
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: | |
M sacc.c | 13 +++++++++---- | |
1 file changed, 9 insertions(+), 4 deletions(-) | |
--- | |
diff --git a/sacc.c b/sacc.c | |
t@@ -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 |