[xiph-commits] r18772 - icecast/trunk/libshout/src

ph3-der-loewe at svn.xiph.org ph3-der-loewe at svn.xiph.org
Wed Jan 16 04:03:03 PST 2013


Author: ph3-der-loewe
Date: 2013-01-16 04:03:03 -0800 (Wed, 16 Jan 2013)
New Revision: 18772

Modified:
   icecast/trunk/libshout/src/shout.c
   icecast/trunk/libshout/src/util.c
Log:
Replaced usage of sprintf() with snprintf().

Modified: icecast/trunk/libshout/src/shout.c
===================================================================
--- icecast/trunk/libshout/src/shout.c	2013-01-16 12:02:14 UTC (rev 18771)
+++ icecast/trunk/libshout/src/shout.c	2013-01-16 12:03:03 UTC (rev 18772)
@@ -507,7 +507,7 @@
 	if (!(self->mount = malloc(len)))
 		return self->error = SHOUTERR_MALLOC;
 
-	sprintf (self->mount, "%s%s", mount[0] == '/' ? "" : "/", mount);
+	snprintf (self->mount, len, "%s%s", mount[0] == '/' ? "" : "/", mount);
 
 	return self->error = SHOUTERR_SUCCESS;
 }
@@ -1161,7 +1161,7 @@
 	len = strlen(self->user) + strlen(self->password) + 2;
 	if (!(in = malloc(len)))
 		return NULL;
-	sprintf(in, "%s:%s", self->user, self->password);
+	snprintf(in, len, "%s:%s", self->user, self->password);
 	out = _shout_util_base64_encode(in);
 	free(in);
 
@@ -1170,7 +1170,7 @@
 		free(out);
 		return NULL;
 	}
-	sprintf(in, "Authorization: Basic %s\r\n", out);
+	snprintf(in, len, "Authorization: Basic %s\r\n", out);
 	free(out);
 	
 	return in;

Modified: icecast/trunk/libshout/src/util.c
===================================================================
--- icecast/trunk/libshout/src/util.c	2013-01-16 12:02:14 UTC (rev 18771)
+++ icecast/trunk/libshout/src/util.c	2013-01-16 12:03:03 UTC (rev 18772)
@@ -252,6 +252,7 @@
   TODO: Memory management needs overhaul. */
 char *_shout_util_dict_urlencode(util_dict *dict, char delim)
 {
+	size_t reslen, resoffset;
 	char *res, *tmp;
 	char *enc;
 	int start = 1;
@@ -266,21 +267,24 @@
 			return NULL;
 		}
 		if (start) {
-			if (!(res = malloc(strlen(enc) + 1))) {
+			reslen = strlen(enc) + 1;
+			if (!(res = malloc(reslen))) {
 				free(enc);
 				return NULL;
 			}
-			sprintf(res, "%s", enc);
+			snprintf(res, reslen, "%s", enc);
 			free(enc);
 			start = 0;
 		} else {
-			if (!(tmp = realloc(res, strlen(res) + strlen(enc) + 2))) {
+			resoffset = strlen(res);
+			reslen = resoffset + strlen(enc) + 2;
+			if (!(tmp = realloc(res, reslen))) {
 				free(enc);
 				free(res);
 				return NULL;
 			} else
 				res = tmp;
-			sprintf(res + strlen(res), "%c%s", delim, enc);
+			snprintf(res + resoffset, reslen - resoffset, "%c%s", delim, enc);
 			free(enc);
 		}
 
@@ -292,13 +296,15 @@
 			return NULL;
 		}
 
-		if (!(tmp = realloc(res, strlen(res) + strlen(enc) + 2))) {
+		resoffset = strlen(res);
+		reslen = resoffset + strlen(enc) + 2;
+		if (!(tmp = realloc(res, reslen))) {
 			free(enc);
 			free(res);
 			return NULL;
 		} else
 			res = tmp;
-		sprintf(res + strlen(res), "=%s", enc);
+		snprintf(res + resoffset, reslen - resoffset, "=%s", enc);
 		free(enc);
 	}
 



More information about the commits mailing list