[Frugalware-git] pacman-g2: Fix overlapping problems in the api

Miklos Vajna vmiklos at frugalware.org
Sun Nov 15 01:42:55 CET 2009


Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=7f66a676e4befd7e99616f54ac8ce060202219d6

commit 7f66a676e4befd7e99616f54ac8ce060202219d6
Author: Laszlo Papp <djszapi2 at gmail.com>
Date:   Fri Nov 13 22:44:22 2009 +0100

Fix overlapping problems in the api

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

diff --git a/lib/libpacman/md5driver.c b/lib/libpacman/md5driver.c
index 39eddfb..32cce79 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);
}


More information about the Frugalware-git mailing list