Browse code

sigtool: improve handling of spaces in cdiffs (bb#2090)

Tomasz Kojm authored on 2011/01/11 02:57:11
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Jan 10 18:43:02 CET 2011 (tk)
2
+---------------------------------
3
+ * sigtool: improve handling of spaces in cdiffs (bb#2090)
4
+
1 5
 Thu Jan  6 14:52:38 CET 2011 (acab)
2 6
 -----------------------------------
3 7
  * libclamav/hashtab.c: properly clear the table
... ...
@@ -1564,7 +1564,7 @@ static int compare(const char *oldpath, const char *newpath, FILE *diff)
1564 1564
 {
1565 1565
 	FILE *old, *new;
1566 1566
 	char *obuff, *nbuff, *tbuff, *pt, *omd5, *nmd5;
1567
-	unsigned int oline = 0, tline, found, i;
1567
+	unsigned int oline = 0, tline, found, i, badxchg = 0;
1568 1568
 	int l1 = 0, l2;
1569 1569
 	long opos;
1570 1570
 
... ...
@@ -1675,6 +1675,10 @@ static int compare(const char *oldpath, const char *newpath, FILE *diff)
1675 1675
 			oline += tline;
1676 1676
 
1677 1677
 		    } else {
1678
+			if(!*obuff || *obuff == ' ') {
1679
+			    badxchg = 1;
1680
+			    break;
1681
+			}
1678 1682
 			obuff[MIN(16, l1-1)] = 0;
1679 1683
 			if((pt = strchr(obuff, ' ')))
1680 1684
 			    *pt = 0;
... ...
@@ -1688,23 +1692,34 @@ static int compare(const char *oldpath, const char *newpath, FILE *diff)
1688 1688
 	    }
1689 1689
 	}
1690 1690
     }
1691
-    fclose(new);
1692 1691
 
1693 1692
     if(old) {
1694
-	while(fgets(obuff, l1, old)) {
1695
-	    oline++;
1696
-	    obuff[MIN(16, l1-1)] = 0;
1697
-	    if((pt = strchr(obuff, ' ')))
1698
-		*pt = 0;
1699
-	    fprintf(diff, "DEL %u %s\n", oline, obuff);
1693
+	if(!badxchg) {
1694
+	    while(fgets(obuff, l1, old)) {
1695
+		oline++;
1696
+		obuff[MIN(16, l1-1)] = 0;
1697
+		if((pt = strchr(obuff, ' ')))
1698
+		    *pt = 0;
1699
+		fprintf(diff, "DEL %u %s\n", oline, obuff);
1700
+	    }
1700 1701
 	}
1701 1702
 	fclose(old);
1702 1703
     }
1703
-
1704 1704
     fprintf(diff, "CLOSE\n");
1705 1705
     free(obuff);
1706
-    free(nbuff);
1707 1706
     free(tbuff);
1707
+    if(badxchg) {
1708
+	fprintf(diff, "UNLINK %s\n", newpath);
1709
+	fprintf(diff, "OPEN %s\n", newpath);
1710
+	rewind(new);
1711
+	while(fgets(nbuff, l1, new)) {
1712
+	    cli_chomp(nbuff);
1713
+	    fprintf(diff, "ADD %s\n", nbuff);
1714
+	}
1715
+	fprintf(diff, "CLOSE\n");
1716
+    }
1717
+    free(nbuff);
1718
+    fclose(new);
1708 1719
     return 0;
1709 1720
 }
1710 1721