[pacman-dev] [patch] alpm_splitdep overwrites input string

ngaba at petra.hos.u-szeged.hu ngaba at petra.hos.u-szeged.hu
Mon Jun 18 10:20:01 EDT 2007


Hi!
I told everything in the subject, patch attached. This also fixes sync300.py
Bye, ngaba


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

-------------- next part --------------
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 66b2d77..22c7347 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -434,21 +434,24 @@ alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
 	return(baddeps);
 }
 
-pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
+pmdepend_t SYMEXPORT *alpm_splitdep(const char *dep_string)
 {
+
 	pmdepend_t *depend;
 	char *ptr = NULL;
 
-	if(depstring == NULL) {
+	if(dep_string == NULL) {
 		return(NULL);
 	}
-	
+
 	depend = malloc(sizeof(pmdepend_t));
 	if(depend == NULL) {
 		_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepend_t));
 		return(NULL);
 	}
 
+	char *depstring = strdup(dep_string);
+
 	/* Find a version comparator if one exists. If it does, set the type and
 	 * increment the ptr accordingly so we can copy the right strings. */
 	if((ptr = strstr(depstring, ">="))) {
@@ -468,6 +471,7 @@ pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
 		depend->mod = PM_DEP_MOD_ANY;
 		strncpy(depend->name, depstring, PKG_NAME_LEN);
 		depend->version[0] = '\0';
+		free(depstring);
 		return(depend);
 	}
 
@@ -475,6 +479,7 @@ pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
 	 * to the right places */
 	strncpy(depend->name, depstring, PKG_NAME_LEN);
 	strncpy(depend->version, ptr, PKG_VERSION_LEN);
+	free(depstring);
 
 	return(depend);
 }


More information about the pacman-dev mailing list