From b14feb7ffbe390762c2bdb4e2e6cc200b2369835 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 21 Jul 2016 23:12:00 +0200 Subject: Add missing part of check_error: copy description (and of course call next_payload) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libcoopgamma.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/libcoopgamma.c b/src/libcoopgamma.c index c6459f4..769b7b8 100644 --- a/src/libcoopgamma.c +++ b/src/libcoopgamma.c @@ -1736,6 +1736,8 @@ static int check_error(libcoopgamma_context_t* restrict ctx, libcoopgamma_async_ int have_in_response_to = 0; int have_error = 0; int bad = 0; + char* payload; + size_t n; for (;;) { @@ -1789,14 +1791,27 @@ static int check_error(libcoopgamma_context_t* restrict ctx, libcoopgamma_async_ return 0; } - if (bad || (have_in_response_to != 1) || (have_error != 1)) + payload = next_payload(ctx, &n); + if (payload != NULL) { - errno = EBADMSG; - copy_errno(ctx); - return -1; + if (memchr(ctx, '\0', n) || (payload[n - 1] != '\n')) + goto badmsg; + ctx->error.description = malloc(n); + if (ctx->error.description == NULL) + goto fail; + memcpy(ctx->error.description, payload, n - 1); + ctx->error.description[n - 1] = '\0'; } + if (bad || (have_in_response_to != 1) || (have_error != 1)) + goto badmsg; + return 1; +badmsg: + errno = EBADMSG; +fail: + copy_errno(ctx); + return -1; } -- cgit v1.2.3-70-g09d2