From ad5b286e06d248a4bd3ed0d32fadbb6ea060b682 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Wed, 17 Jan 2007 21:29:17 -0500 Subject: [PATCH] Fix for protocol command lengths > 8196. --- libpwmd/pwmc.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/libpwmd/pwmc.c b/libpwmd/pwmc.c index b25afe23..38b55b88 100644 --- a/libpwmd/pwmc.c +++ b/libpwmd/pwmc.c @@ -64,6 +64,8 @@ int main(int argc, char *argv[]) pwm_t *pwm; char *result = NULL; int save = 0; + char *buf = NULL; + int total = 0; while ((opt = getopt(argc, argv, "hvap:s:S")) != EOF) { switch (opt) { @@ -140,13 +142,42 @@ int main(int argc, char *argv[]) } while ((p = fgets(command, sizeof(command), stdin)) != NULL) { - if ((ret = pwmd_command(pwm, &result, &error, PWMD_COMMAND, command)) != PWMD_OK) { + int len = strlen(p); + + if (p[len - 1] != '\n') { + if ((buf = realloc(buf, (total + len + 1) * sizeof(char))) == NULL) + err(EXIT_FAILURE, "realloc()"); + + memcpy(&buf[total], p, len); + total += len; + buf[total] = 0; + continue; + } + else { + if (buf) { + if ((buf = realloc(buf, (total + len + 1) * sizeof(char))) == NULL) + err(EXIT_FAILURE, "realloc()"); + + memcpy(&buf[total], p, len); + total += len; + buf[total] = 0; + } + } + + if ((ret = pwmd_command(pwm, &result, &error, PWMD_COMMAND, + (buf) ? buf : command)) != PWMD_OK) { memset(&command, 0, sizeof(command)); pwmd_show_error(ret, error); pwmd_close(pwm); exit(EXIT_FAILURE); } + if (buf) { + free(buf); + buf = NULL; + total = 0; + } + if (result) { printf("%s\n", (char *)result); free(result); -- 2.11.4.GIT