[xiph-commits] r18773 - icecast/branches/ph3/libshout/src

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


Author: ph3-der-loewe
Date: 2013-01-16 04:07:15 -0800 (Wed, 16 Jan 2013)
New Revision: 18773

Modified:
   icecast/branches/ph3/libshout/src/shout.c
   icecast/branches/ph3/libshout/src/util.c
Log:
sync with master

Modified: icecast/branches/ph3/libshout/src/shout.c
===================================================================
--- icecast/branches/ph3/libshout/src/shout.c	2013-01-16 12:03:03 UTC (rev 18772)
+++ icecast/branches/ph3/libshout/src/shout.c	2013-01-16 12:07:15 UTC (rev 18773)
@@ -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/branches/ph3/libshout/src/util.c
===================================================================
--- icecast/branches/ph3/libshout/src/util.c	2013-01-16 12:03:03 UTC (rev 18772)
+++ icecast/branches/ph3/libshout/src/util.c	2013-01-16 12:07:15 UTC (rev 18773)
@@ -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