2014-10-17 19:56:45 +00:00
|
|
|
$OpenBSD: patch-fdupes_c,v 1.2 2014/10/17 19:56:45 sthen Exp $
|
|
|
|
--- fdupes.c.orig Sat Apr 20 19:21:46 2013
|
|
|
|
+++ fdupes.c Fri Oct 17 20:51:45 2014
|
|
|
|
@@ -36,6 +36,11 @@
|
2008-06-20 06:03:43 +00:00
|
|
|
#include "md5/md5.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
+#ifdef HAVE_MD5
|
|
|
|
+#include <sys/types.h>
|
|
|
|
+#include <md5.h>
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
#define ISFLAG(a,b) ((a & b) == b)
|
|
|
|
#define SETFLAG(a,b) (a |= b)
|
|
|
|
|
2014-10-17 19:56:45 +00:00
|
|
|
@@ -113,11 +118,13 @@ void escapefilename(char *escape_list, char **filename
|
2008-06-20 06:03:43 +00:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int tx;
|
|
|
|
+ size_t l;
|
|
|
|
char *tmp;
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
filename = *filename_ptr;
|
|
|
|
|
|
|
|
+ l = strlen(filename) * 2 + 1;
|
|
|
|
tmp = (char*) malloc(strlen(filename) * 2 + 1);
|
|
|
|
if (tmp == NULL) {
|
|
|
|
errormsg("out of memory!\n");
|
2014-10-17 19:56:45 +00:00
|
|
|
@@ -137,7 +144,7 @@ void escapefilename(char *escape_list, char **filename
|
2008-06-20 06:03:43 +00:00
|
|
|
errormsg("out of memory!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
- strcpy(*filename_ptr, tmp);
|
|
|
|
+ strlcpy(*filename_ptr, tmp, l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-17 19:56:45 +00:00
|
|
|
@@ -236,6 +243,7 @@ int grokdir(char *dir, file_t **filelistp)
|
2008-06-20 06:03:43 +00:00
|
|
|
struct dirent *dirinfo;
|
|
|
|
int lastchar;
|
|
|
|
int filecount = 0;
|
|
|
|
+ size_t l;
|
|
|
|
struct stat info;
|
|
|
|
struct stat linfo;
|
|
|
|
static int progress = 0;
|
2014-10-17 19:56:45 +00:00
|
|
|
@@ -270,7 +278,8 @@ int grokdir(char *dir, file_t **filelistp)
|
2008-06-20 06:03:43 +00:00
|
|
|
newfile->duplicates = NULL;
|
|
|
|
newfile->hasdupes = 0;
|
|
|
|
|
|
|
|
- newfile->d_name = (char*)malloc(strlen(dir)+strlen(dirinfo->d_name)+2);
|
|
|
|
+ l = strlen(dir)+strlen(dirinfo->d_name)+2;
|
|
|
|
+ newfile->d_name = (char*)malloc(l);
|
|
|
|
|
|
|
|
if (!newfile->d_name) {
|
|
|
|
errormsg("out of memory!\n");
|
2014-10-17 19:56:45 +00:00
|
|
|
@@ -279,11 +288,11 @@ int grokdir(char *dir, file_t **filelistp)
|
2008-06-20 06:03:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
- strcpy(newfile->d_name, dir);
|
|
|
|
+ strlcpy(newfile->d_name, dir, l);
|
|
|
|
lastchar = strlen(dir) - 1;
|
|
|
|
if (lastchar >= 0 && dir[lastchar] != '/')
|
|
|
|
- strcat(newfile->d_name, "/");
|
|
|
|
- strcat(newfile->d_name, dirinfo->d_name);
|
|
|
|
+ strlcat(newfile->d_name, "/", l);
|
|
|
|
+ strlcat(newfile->d_name, dirinfo->d_name, l);
|
|
|
|
|
|
|
|
if (filesize(newfile->d_name) == 0 && ISFLAG(flags, F_EXCLUDEEMPTY)) {
|
|
|
|
free(newfile->d_name);
|
2014-10-17 19:56:45 +00:00
|
|
|
@@ -334,14 +343,22 @@ char *getcrcsignatureuntil(char *filename, off_t max_r
|
2008-06-20 06:03:43 +00:00
|
|
|
int x;
|
|
|
|
off_t fsize;
|
|
|
|
off_t toread;
|
|
|
|
+#ifdef HAVE_MD5
|
|
|
|
+ MD5_CTX state;
|
|
|
|
+#else
|
|
|
|
md5_state_t state;
|
|
|
|
+#endif
|
|
|
|
md5_byte_t digest[16];
|
|
|
|
static md5_byte_t chunk[CHUNK_SIZE];
|
|
|
|
static char signature[16*2 + 1];
|
|
|
|
char *sigp;
|
|
|
|
FILE *file;
|
|
|
|
-
|
|
|
|
+
|
|
|
|
+#ifdef HAVE_MD5
|
|
|
|
+ MD5Init(&state);
|
|
|
|
+#else
|
|
|
|
md5_init(&state);
|
|
|
|
+#endif
|
|
|
|
|
2014-10-17 19:56:45 +00:00
|
|
|
|
2008-06-20 06:03:43 +00:00
|
|
|
fsize = filesize(filename);
|
2014-10-17 19:56:45 +00:00
|
|
|
@@ -362,16 +379,24 @@ char *getcrcsignatureuntil(char *filename, off_t max_r
|
|
|
|
fclose(file);
|
2008-06-20 06:03:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
+#ifdef HAVE_MD5
|
|
|
|
+ MD5Update(&state, chunk, toread);
|
|
|
|
+#else
|
|
|
|
md5_append(&state, chunk, toread);
|
|
|
|
+#endif
|
|
|
|
fsize -= toread;
|
|
|
|
}
|
|
|
|
|
|
|
|
+#ifdef HAVE_MD5
|
|
|
|
+ MD5Final(digest, &state);
|
|
|
|
+#else
|
|
|
|
md5_finish(&state, digest);
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
sigp = signature;
|
|
|
|
|
|
|
|
for (x = 0; x < 16; x++) {
|
|
|
|
- sprintf(sigp, "%02x", digest[x]);
|
|
|
|
+ snprintf(sigp, 2, "%02x", digest[x]);
|
|
|
|
sigp = strchr(sigp, '\0');
|
|
|
|
}
|
|
|
|
|
2014-10-17 19:56:45 +00:00
|
|
|
@@ -471,6 +496,7 @@ file_t **checkmatch(filetree_t **root, filetree_t *che
|
2008-06-20 06:03:43 +00:00
|
|
|
{
|
|
|
|
int cmpresult;
|
|
|
|
char *crcsignature;
|
|
|
|
+ size_t l;
|
|
|
|
off_t fsize;
|
|
|
|
|
2014-10-17 19:56:45 +00:00
|
|
|
/* If device and inode fields are equal one of the files is a
|
|
|
|
@@ -494,24 +520,26 @@ file_t **checkmatch(filetree_t **root, filetree_t *che
|
|
|
|
crcsignature = getcrcpartialsignature(checktree->file->d_name);
|
2008-06-20 06:03:43 +00:00
|
|
|
if (crcsignature == NULL) return NULL;
|
|
|
|
|
2014-10-17 19:56:45 +00:00
|
|
|
- checktree->file->crcpartial = (char*) malloc(strlen(crcsignature)+1);
|
2008-06-20 06:03:43 +00:00
|
|
|
+ l = strlen(crcsignature)+1;
|
2014-10-17 19:56:45 +00:00
|
|
|
+ checktree->file->crcpartial = (char*) malloc(l);
|
|
|
|
if (checktree->file->crcpartial == NULL) {
|
2008-06-20 06:03:43 +00:00
|
|
|
errormsg("out of memory\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2014-10-17 19:56:45 +00:00
|
|
|
- strcpy(checktree->file->crcpartial, crcsignature);
|
|
|
|
+ strlcpy(checktree->file->crcpartial, crcsignature, l);
|
2008-06-20 06:03:43 +00:00
|
|
|
}
|
|
|
|
|
2014-10-17 19:56:45 +00:00
|
|
|
if (file->crcpartial == NULL) {
|
|
|
|
crcsignature = getcrcpartialsignature(file->d_name);
|
2008-06-20 06:03:43 +00:00
|
|
|
if (crcsignature == NULL) return NULL;
|
|
|
|
|
2014-10-17 19:56:45 +00:00
|
|
|
- file->crcpartial = (char*) malloc(strlen(crcsignature)+1);
|
2008-06-20 06:03:43 +00:00
|
|
|
+ l = strlen(crcsignature)+1;
|
2014-10-17 19:56:45 +00:00
|
|
|
+ file->crcpartial = (char*) malloc(l);
|
|
|
|
if (file->crcpartial == NULL) {
|
2008-06-20 06:03:43 +00:00
|
|
|
errormsg("out of memory\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2014-10-17 19:56:45 +00:00
|
|
|
- strcpy(file->crcpartial, crcsignature);
|
|
|
|
+ strlcpy(file->crcpartial, crcsignature, l);
|
2008-06-20 06:03:43 +00:00
|
|
|
}
|
|
|
|
|
2014-10-17 19:56:45 +00:00
|
|
|
cmpresult = strcmp(file->crcpartial, checktree->file->crcpartial);
|
|
|
|
@@ -1164,7 +1192,7 @@ int main(int argc, char **argv) {
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
- stdin = freopen("/dev/tty", "r", stdin);
|
|
|
|
+ /* stdin isn't usable as an lvalue ... stdin = freopen("/dev/tty", "r", stdin); */
|
|
|
|
deletefiles(files, 1, stdin);
|
|
|
|
}
|
|
|
|
}
|