From: Florian Forster Date: Thu, 3 Jul 2008 08:42:45 +0000 (+0200) Subject: src/rrd_daemon.c: Catch invalid uses of `flush'. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=5a1cca15009ed7ebfad7ce7a0c8bd55d38e7dfac;p=rrdtool.git src/rrd_daemon.c: Catch invalid uses of `flush'. And don't run into an assertion in that case. --- 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));