[MPlayer-cvslog] r35307 - trunk/stream/cookies.c

reimar subversion at mplayerhq.hu
Wed Oct 31 20:01:55 CET 2012


Author: reimar
Date: Wed Oct 31 20:01:55 2012
New Revision: 35307

Log:
Use snprintf instead of sprintf.

No good reason beyond paranoia and Coverity complaining about it.
In a very theoretical, construed case the adds might overflow
or the environment might change in-between the getenv calls.

Modified:
   trunk/stream/cookies.c

Modified: trunk/stream/cookies.c
==============================================================================
--- trunk/stream/cookies.c	Wed Oct 31 19:55:33 2012	(r35306)
+++ trunk/stream/cookies.c	Wed Oct 31 20:01:55 2012	(r35307)
@@ -205,11 +205,13 @@ static struct cookie_list_type *load_coo
     if (dir) {
 	while ((ent = readdir(dir)) != NULL) {
 	    if ((ent->d_name)[0] != '.') {
-		buf = malloc(strlen(getenv("HOME")) +
-                             sizeof("/.mozilla/default/") +
-                             strlen(ent->d_name) + sizeof("cookies.txt") + 1);
-		sprintf(buf, "%s/.mozilla/default/%s/cookies.txt",
-			 getenv("HOME"), ent->d_name);
+		const char *home = getenv("HOME");
+		unsigned len = strlen(home) +
+		               sizeof("/.mozilla/default/") +
+		               strlen(ent->d_name) + sizeof("cookies.txt") + 1;
+		buf = malloc(len);
+		snprintf(buf, len, "%s/.mozilla/default/%s/cookies.txt",
+			 home, ent->d_name);
 		list = load_cookies_from(buf, list);
 		free(buf);
 	    }


More information about the MPlayer-cvslog mailing list