diff --git a/daemon/cli.c b/daemon/cli.c index 731b5d67f..711812531 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -306,7 +306,7 @@ next: nfd = accept(fd, (struct sockaddr *) &sin, &sinl); if (nfd == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { - sprintf(replybuffer, "Could currently not accept CLI commands. Reason:%s\n", strerror(errno)); + ilog(LOG_INFO, "Could currently not accept CLI commands. Reason:%s", strerror(errno)); goto cleanup; } ilog(LOG_INFO, "Accept error:%s", strerror(errno)); @@ -325,17 +325,18 @@ next: ilog(LOG_INFO, "Could currently not read CLI commands. Reason:%s", strerror(errno)); } inlen += readbytes; - } while (readbytes > 0); + } while (readbytes > 0 && inlen < sizeof(inbuf)-1); + inbuf[inlen] = 0; ilog(LOG_INFO, "Got CLI command:%s",inbuf); static const char* LIST = "list"; static const char* TERMINATE = "terminate"; - if (inlen>=strlen(LIST) && strncmp(inbuf,LIST,strlen(LIST)) == 0) { + if (strncmp(inbuf,LIST,strlen(LIST)) == 0) { cli_incoming_list(inbuf+strlen(LIST), inlen-strlen(LIST), cli->callmaster, outbuf, outbufend); - } else if (inlen>=strlen(TERMINATE) && strncmp(inbuf,TERMINATE,strlen(TERMINATE)) == 0) { + } else if (strncmp(inbuf,TERMINATE,strlen(TERMINATE)) == 0) { cli_incoming_terminate(inbuf+strlen(TERMINATE), inlen-strlen(TERMINATE), cli->callmaster, outbuf, outbufend); } else { sprintf(replybuffer, "%s:%s\n", "Unknown or incomplete command:", inbuf); diff --git a/daemon/graphite.c b/daemon/graphite.c index f22c1bd9b..8e5f8fca4 100644 --- a/daemon/graphite.c +++ b/daemon/graphite.c @@ -118,7 +118,7 @@ int send_graphite_data() { rc = sprintf(ptr,"%s.totals.silent_timeout_sess "UINT64F" %llu\n",hostname, atomic64_get_na(&ts.total_silent_timeout_sess),(unsigned long long)g_now); ptr += rc; rc = sprintf(ptr,"%s.totals.timeout_sess "UINT64F" %llu\n",hostname, atomic64_get_na(&ts.total_timeout_sess),(unsigned long long)g_now); ptr += rc; - rc = write(graphite_sock, data_to_send, strlen(data_to_send)); + rc = write(graphite_sock, data_to_send, ptr - data_to_send); if (rc<0) { ilog(LOG_ERROR,"Could not write to graphite socket. Disconnecting graphite server."); goto error;