[Frugalware-devel] [PATCH] Fix overlapping problems in the api

Laszlo Papp djszapi2 at gmail.com
Sun Nov 15 01:43:58 CET 2009


Fix the next errors in the api:

[./lib/libpacman/md5driver.c:67]: (error) Overlapping data buffer ret
[./lib/libpacman/sha1.c:409]: (error) Overlapping data buffer ret
---
 lib/libpacman/md5driver.c |    9 +++++----
 lib/libpacman/sha1.c      |    6 ++++--
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/lib/libpacman/md5driver.c b/lib/libpacman/md5driver.c
index 39eddfb..6def8f5 100644
--- a/lib/libpacman/md5driver.c
+++ b/lib/libpacman/md5driver.c
@@ -42,14 +42,14 @@ char* _pacman_MDFile(char *filename)
 {
 	FILE *file;
 	MD_CTX context;
-	int len;
+	int len = 0;
 	unsigned char buffer[1024], digest[16];
 
 	if((file = fopen(filename, "rb")) == NULL) {
 		printf (_("%s can't be opened\n"), filename);
 	} else {
 		char *ret;
-		int i;
+		int i, x;
 
 		MDInit(&context);
 		while((len = fread(buffer, 1, 1024, file))) {
@@ -64,9 +64,10 @@ char* _pacman_MDFile(char *filename)
 		ret = (char*)malloc(33);
 		ret[0] = '\0';
 		for(i = 0; i < 16; i++) {
-			sprintf(ret, "%s%02x", ret, digest[i]);
+		    x = sprintf(ret + len, "%02x", digest[i]);
+		    if (x >= 0) { len+= x; }
 		}
-
+		ret[32] = '\0';
 		return(ret);
 	}
 	return(NULL);
diff --git a/lib/libpacman/sha1.c b/lib/libpacman/sha1.c
index 19a7118..d5ae9c8 100644
--- a/lib/libpacman/sha1.c
+++ b/lib/libpacman/sha1.c
@@ -387,7 +387,7 @@ documentation and/or software.
 char* _pacman_SHAFile(char *filename) {
     FILE *file;
     struct sha_ctx context;
-    int len, i;
+    int len = 0, i, x;
     unsigned char buffer[1024], digest[20];
     char *ret;
 
@@ -406,8 +406,10 @@ char* _pacman_SHAFile(char *filename) {
 	ret = (char*)malloc(41);
 	ret[0] = '\0';
 	for(i = 0; i < 20; i++) {
-	    sprintf(ret, "%s%02x", ret, digest[i]);
+	    x = sprintf(ret + len, "%02x", digest[i]);
+	    if (x >= 0) { len += x; }
 	}
+	ret[40] = '\0';
 	return(ret);
     }
 
-- 
1.6.5



More information about the Frugalware-devel mailing list