* Copyright (C) 1996-2000 Andrew Tridgell
* Copyright (C) 1996 Paul Mackerras
* Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2015 Wayne Davison
+ * Copyright (C) 2003-2018 Wayne Davison
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if (errno != ENOSYS)
return -1;
switch_step++;
- /* FALLTHROUGH */
#endif
#ifdef HAVE_UTIMENSAT
if (errno != ENOSYS)
return -1;
switch_step++;
- /* FALLTHROUGH */
#endif
#ifdef HAVE_LUTIMES
if (errno != ENOSYS)
return -1;
switch_step++;
- /* FALLTHROUGH */
#endif
#include "case_N.h"
if (S_ISLNK(mode))
return 1;
}
- /* FALLTHROUGH */
#include "case_N.h"
#ifdef HAVE_UTIMES
if (robust_unlink(dest) && errno != ENOENT) {
int save_errno = errno;
rsyserr(FERROR_XFER, errno, "unlink %s", full_fname(dest));
+ close(ifd);
errno = save_errno;
return -1;
}
int rlen = 0, drop_dot_dirs = !relative_paths || !(flags & SP_KEEP_DOT_DIRS);
if (dest != p) {
- int plen = strlen(p);
+ int plen = strlen(p); /* the path len INCLUDING any separating slash */
if (*p == '/') {
if (!rootdir)
rootdir = module_dir;
if (dest) {
if (rlen + plen + 1 >= MAXPATHLEN)
return NULL;
- } else if (!(dest = new_array(char, rlen + plen + 1)))
+ } else if (!(dest = new_array(char, MAX(rlen + plen + 1, 2))))
out_of_memory("sanitize_path");
- if (rlen) {
+ if (rlen) { /* only true if p previously started with a slash */
memcpy(dest, rootdir, rlen);
- if (rlen > 1)
+ if (rlen > 1) /* a rootdir of len 1 is "/", so this avoids a 2nd slash */
dest[rlen++] = '/';
}
}
}
return (char*)lp->items + (lp->count++ * item_size);
}
+
+/* This zeroing of memory won't be optimized away by the compiler. */
+void force_memzero(void *buf, size_t len)
+{
+ volatile uchar *z = buf;
+ while (len-- > 0)
+ *z++ = '\0';
+}