Source: Peter Volkov Upstream: notified (sent email to Reason: bugs.gentoo.org/237828 comment #1 With USE=md5sum-external fails on filenames with spaces in their names. Updated on 2009/06/20: * Fixed free due to wrong length of memory allocation bugs.gentoo.org/273597 * Now works with filename that have " in name... --- fdupes.c 2009-06-20 10:51:31 +0000 +++ fdupes.c 2009-06-20 13:38:39 +0000 @@ -291,17 +291,48 @@ char *getcrcsignature(char *filename) { static char signature[256]; + char *backslashedfilename; char *command; char *separator; FILE *result; - - command = (char*) malloc(strlen(filename)+strlen(EXTERNAL_MD5)+2); + int i=0; + int j=0; + int numofquotes=0; + + /* Find number of " in filename */ + while ( filename[i] != '\0' ) { + if ( filename[i] == '\"' ) + numofquotes++; + i++; + } + + backslashedfilename = (char*) malloc(strlen(filename)+numofquotes+1); + if (backslashedfilename == NULL) { + errormsg("out of memory\n"); + exit(1); + } + + /* Put backslash before each " */ + i=0; + while ( filename[i] != '\0' ) { + if ( filename[i] == '\"' ) { + backslashedfilename[j]='\\'; + j++; + } + backslashedfilename[j]=filename[i]; + i++; + j++; + } + backslashedfilename[j]='\0'; + + command = (char*) malloc(strlen(backslashedfilename)+strlen(EXTERNAL_MD5)+6); if (command == NULL) { errormsg("out of memory\n"); exit(1); } - sprintf(command, "%s %s", EXTERNAL_MD5, filename); + /* Qoutation required to works spaces in filenames */ + sprintf(command, "%s \"%s\"", EXTERNAL_MD5, backslashedfilename); result = popen(command, "r"); if (result == NULL) { @@ -309,6 +340,7 @@ exit(1); } + free(backslashedfilename); free(command); if (fgets(signature, 256, result) == NULL) {