[Freeswitch-svn] [commit] r10907 - in freeswitch/trunk/libs/esl/src: . include

FreeSWITCH SVN mikej at freeswitch.org
Mon Dec 22 08:27:41 PST 2008


Author: mikej
Date: Mon Dec 22 11:27:39 2008
New Revision: 10907

Log:
null terminating snprintf

Modified:
   freeswitch/trunk/libs/esl/src/esl.c
   freeswitch/trunk/libs/esl/src/esl_config.c
   freeswitch/trunk/libs/esl/src/esl_event.c
   freeswitch/trunk/libs/esl/src/include/esl.h

Modified: freeswitch/trunk/libs/esl/src/esl.c
==============================================================================
--- freeswitch/trunk/libs/esl/src/esl.c	(original)
+++ freeswitch/trunk/libs/esl/src/esl.c	Mon Dec 22 11:27:39 2008
@@ -175,6 +175,24 @@
 	return NULL;
 }
 
+#ifdef WIN32
+#ifndef vsnprintf
+#define vsnprintf _vsnprintf
+#endif
+#endif
+
+int esl_snprintf(char *buffer, size_t count, const char *fmt, ...)
+{
+	va_list ap;
+	int ret;
+
+	va_start(ap, fmt);
+	ret = vsnprintf(buffer, count-1, fmt, ap);
+	if (ret < 0)
+		buffer[count-1] = '\0';
+	va_end(ap);
+	return ret;
+}
 
 static void null_logger(const char *file, const char *func, int line, int level, const char *fmt, ...)
 {

Modified: freeswitch/trunk/libs/esl/src/esl_config.c
==============================================================================
--- freeswitch/trunk/libs/esl/src/esl_config.c	(original)
+++ freeswitch/trunk/libs/esl/src/esl_config.c	Mon Dec 22 11:27:39 2008
@@ -43,7 +43,7 @@
 	if (file_path[0] == '/') {
 		path = file_path;
 	} else {
-		snprintf(path_buf, sizeof(path_buf), "%s%s%s", ESL_CONFIG_DIR, ESL_PATH_SEPARATOR, file_path);
+		esl_snprintf(path_buf, sizeof(path_buf), "%s%s%s", ESL_CONFIG_DIR, ESL_PATH_SEPARATOR, file_path);
 		path = path_buf;
 	}
 
@@ -61,7 +61,7 @@
 			int last = -1;
 			char *var, *val;
 
-			snprintf(path_buf, sizeof(path_buf), "%s%sopenesl.conf", ESL_CONFIG_DIR, ESL_PATH_SEPARATOR);
+			esl_snprintf(path_buf, sizeof(path_buf), "%s%sopenesl.conf", ESL_CONFIG_DIR, ESL_PATH_SEPARATOR);
 			path = path_buf;
 
 			if ((f = fopen(path, "r")) == 0) {

Modified: freeswitch/trunk/libs/esl/src/esl_event.c
==============================================================================
--- freeswitch/trunk/libs/esl/src/esl_event.c	(original)
+++ freeswitch/trunk/libs/esl/src/esl_event.c	Mon Dec 22 11:27:39 2008
@@ -481,7 +481,7 @@
 		if (encode) {
 			esl_url_encode(hp->value, encode_buf, encode_len);
 		} else {
-			snprintf(encode_buf, encode_len, "[%s]", hp->value);
+			esl_snprintf(encode_buf, encode_len, "[%s]", hp->value);
 		}
 
 		llen = strlen(hp->name) + strlen(encode_buf) + 8;

Modified: freeswitch/trunk/libs/esl/src/include/esl.h
==============================================================================
--- freeswitch/trunk/libs/esl/src/include/esl.h	(original)
+++ freeswitch/trunk/libs/esl/src/include/esl.h	Mon Dec 22 11:27:39 2008
@@ -284,6 +284,8 @@
 const char *esl_stristr(const char *instr, const char *str);
 int esl_toupper(int c);
 int esl_tolower(int c);
+int esl_snprintf(char *buffer, size_t count, const char *fmt, ...);
+
 
 typedef void (*esl_listen_callback_t)(esl_socket_t server_sock, esl_socket_t client_sock, struct sockaddr_in addr);
 



More information about the Freeswitch-svn mailing list