[monitoring-plugins] plugins/check_real.c - recv string null terminate

Jan Wagner git at monitoring-plugins.org
Sat Jun 28 22:20:08 CEST 2014


    Module: monitoring-plugins
    Branch: master
    Commit: b61f51ad0291cf7051b6ea15ec8f8486f02443f9
    Author: Spenser Reinhardt <sreinhardt at nagios.com>
 Committer: Jan Wagner <waja at cyconet.org>
      Date: Thu Jun  5 23:01:35 2014 -0500
       URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=b61f51a

plugins/check_real.c - recv string null terminate

Recv into buffer is not properly null terminated prior to strstr and possible other string functions expecting a null termination. Simply take bytes received and use as an index to append \0 after. We are creating buffer[] with size of MAX_INPUT_BUFFER and recv with MAX_INPUT_BUFFER-1 so this should never overflow.

---

 plugins/check_real.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/check_real.c b/plugins/check_real.c
index 47776c5..36f6413 100644
--- a/plugins/check_real.c
+++ b/plugins/check_real.c
@@ -178,6 +178,7 @@ main (int argc, char **argv)
 
 		/* watch for the REAL connection string */
 		result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0);
+		buffer[result] = "\0"; /* null terminate recieved buffer */
 
 		/* return a CRITICAL status if we couldn't read any data */
 		if (result == -1) {



More information about the Commits mailing list