commit 34fd4f17068b408353bb6ae1df3eb4a58c259e25 Quentin Rameau <quinq@fifth.space> 2021-01-30 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!
sacc.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/sacc.c b/sacc.c index 74f41cb..0b54ddc 100644 --- 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