diff --git a/WINGs/wcolorpanel.c b/WINGs/wcolorpanel.c index c86dfdd7..eb019470 100644 --- a/WINGs/wcolorpanel.c +++ b/WINGs/wcolorpanel.c @@ -3342,8 +3342,16 @@ static int fetchFile(char *toPath, char *srcFile, char *destFile) FILE *src, *dst; size_t nread, nwritten; char *dstpath; + struct stat st; char buf[BUFSIZE]; + /* only to a directory */ + if (stat(toPath, &st) != 0 || !S_ISDIR(st.st_mode)) + return -1; + /* only copy files */ + if (stat(srcFile, &st) != 0 || !S_ISREG(st.st_mode)) + return -1; + RETRY( src = fopen(srcFile, "rb") ) if (src == NULL) { werror(_("Could not open %s"), srcFile); @@ -3374,10 +3382,11 @@ static int fetchFile(char *toPath, char *srcFile, char *destFile) unlink(dstpath); RETRY( fclose(src) ) + fchmod(fileno(dst), st.st_mode); fsync(fileno(dst)); RETRY( fclose(dst) ) - wfree(dstpath); + return 0; }