From 5a1cca15009ed7ebfad7ce7a0c8bd55d38e7dfac Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 3 Jul 2008 10:42:45 +0200 Subject: [PATCH] src/rrd_daemon.c: Catch invalid uses of `flush'. And don't run into an assertion in that case. --- src/rrd_daemon.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c index 024738b..1f961db 100644 --- a/src/rrd_daemon.c +++ b/src/rrd_daemon.c @@ -516,6 +516,9 @@ static int buffer_get_field (char **buffer_ret, /* {{{ */ field = *buffer_ret; field_size = 0; + if (buffer_size <= 0) + return (-1); + /* This is ensured by `handle_request'. */ assert (buffer[buffer_size - 1] == ' '); @@ -668,19 +671,20 @@ static int handle_request_flush (int fd, /* {{{ */ status = buffer_get_field (&buffer, &buffer_size, &file); if (status != 0) { - RRDD_LOG (LOG_INFO, "handle_request_flush: Cannot get file name."); - return (-1); + strncpy (result, "-1 Usage: flush \n", sizeof (result)); } - - status = flush_file (file); - if (status == 0) - snprintf (result, sizeof (result), "0 Successfully flushed %s.\n", file); - else if (status == ENOENT) - snprintf (result, sizeof (result), "-1 No such file: %s.\n", file); - else if (status < 0) - strncpy (result, "-1 Internal error.\n", sizeof (result)); else - snprintf (result, sizeof (result), "-1 Failed with status %i.\n", status); + { + status = flush_file (file); + if (status == 0) + snprintf (result, sizeof (result), "0 Successfully flushed %s.\n", file); + else if (status == ENOENT) + snprintf (result, sizeof (result), "-1 No such file: %s.\n", file); + else if (status < 0) + strncpy (result, "-1 Internal error.\n", sizeof (result)); + else + snprintf (result, sizeof (result), "-1 Failed with status %i.\n", status); + } result[sizeof (result) - 1] = 0; status = write (fd, result, strlen (result)); -- 2.11.0