=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rsync/flist.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- src/usr.bin/rsync/flist.c 2019/02/11 19:18:36 1.4 +++ src/usr.bin/rsync/flist.c 2019/02/11 21:41:22 1.5 @@ -1,4 +1,4 @@ -/* $Id: flist.c,v 1.4 2019/02/11 19:18:36 deraadt Exp $ */ +/* $Id: flist.c,v 1.5 2019/02/11 21:41:22 deraadt Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -69,13 +69,13 @@ struct flist *new; struct flist *f, *fnext; - if (0 == *sz) + if (*sz == 0) return 1; /* Create a new buffer, "new", and copy. */ new = calloc(*sz, sizeof(struct flist)); - if (NULL == new) { + if (new == NULL) { ERR(sess, "calloc"); return 0; } @@ -98,7 +98,7 @@ * destination side. */ - if (0 == strcmp(f->path, fnext->path)) { + if (strcmp(f->path, fnext->path) == 0) { new[j++] = *f; i++; WARNX(sess, "%s: duplicate path: %s", @@ -155,7 +155,7 @@ if (!S_ISDIR(fl[i].st.mode)) continue; cp = strchr(fl[i].wpath, '/'); - if (NULL != cp && '\0' != cp[1]) + if (cp != NULL && cp[1] != '\0') continue; fl[i].st.flags |= FLSTAT_TOP_DIR; LOG4(sess, "%s: top-level", fl[i].wpath); @@ -176,25 +176,25 @@ flist_fts_check(struct sess *sess, FTSENT *ent) { - if (FTS_F == ent->fts_info || - FTS_D == ent->fts_info || - FTS_SL == ent->fts_info || - FTS_SLNONE == ent->fts_info) + if (ent->fts_info == FTS_F || + ent->fts_info == FTS_D || + ent->fts_info == FTS_SL || + ent->fts_info == FTS_SLNONE) return 1; - if (FTS_DC == ent->fts_info) { + if (ent->fts_info == FTS_DC) { WARNX(sess, "%s: directory cycle", ent->fts_path); - } else if (FTS_DNR == ent->fts_info) { + } else if (ent->fts_info == FTS_DNR) { errno = ent->fts_errno; WARN(sess, "%s: unreadable directory", ent->fts_path); - } else if (FTS_DOT == ent->fts_info) { + } else if (ent->fts_info == FTS_DOT) { WARNX(sess, "%s: skipping dot-file", ent->fts_path); - } else if (FTS_ERR == ent->fts_info) { + } else if (ent->fts_info == FTS_ERR) { errno = ent->fts_errno; WARN(sess, "%s", ent->fts_path); - } else if (FTS_DEFAULT == ent->fts_info) { + } else if (ent->fts_info == FTS_DEFAULT) { WARNX(sess, "%s: skipping special", ent->fts_path); - } else if (FTS_NS == ent->fts_info) { + } else if (ent->fts_info == FTS_NS) { errno = ent->fts_errno; WARN(sess, "%s: could not stat", ent->fts_path); } @@ -220,7 +220,7 @@ { size_t i; - if (NULL == f) + if (f == NULL) return; for (i = 0; i < sz; i++) { @@ -384,13 +384,13 @@ /* Allocate our full filename length. */ /* FIXME: maximum pathname length. */ - if (0 == (len = pathlen + partial)) { + if ((len = pathlen + partial) == 0) { ERRX(sess, "security violation: " "zero-length pathname"); return 0; } - if (NULL == (f->path = malloc(len + 1))) { + if ((f->path = malloc(len + 1)) == NULL) { ERR(sess, "malloc"); return 0; } @@ -404,16 +404,16 @@ return 0; } - if ('/' == f->path[0]) { + if (f->path[0] == '/') { ERRX(sess, "security violation: " "absolute pathname: %s", f->path); return 0; } - if (NULL != strstr(f->path, "/../") || - (len > 2 && 0 == strcmp(f->path + len - 3, "/..")) || - (len > 2 && 0 == strncmp(f->path, "../", 3)) || - 0 == strcmp(f->path, "..")) { + if (strstr(f->path, "/../") != NULL || + (len > 2 && strcmp(f->path + len - 3, "/..") == 0) || + (len > 2 && strncmp(f->path, "../", 3) == 0) || + strcmp(f->path, "..") == 0) { ERRX(sess, "%s: security violation: " "backtracking pathname", f->path); return 0; @@ -442,7 +442,7 @@ pp = recallocarray(*fl, *max, *max + FLIST_CHUNK_SIZE, sizeof(struct flist)); - if (NULL == pp) { + if (pp == NULL) { ERR(sess, "recallocarray"); return 0; } @@ -467,12 +467,12 @@ * only the filename part for the receiver. */ - if (NULL == (f->path = strdup(path))) { + if ((f->path = strdup(path)) == NULL) { ERR(sess, "strdup"); return 0; } - if (NULL == (f->wpath = strrchr(f->path, '/'))) + if ((f->wpath = strrchr(f->path, '/')) == NULL) f->wpath = f->path; else f->wpath++; @@ -489,7 +489,7 @@ if (S_ISLNK(st->st_mode)) { f->link = symlink_read(sess, f->path); - if (NULL == f->link) { + if (f->link == NULL) { ERRX1(sess, "symlink_read"); return 0; } @@ -521,7 +521,7 @@ if (!io_read_byte(sess, fd, &flag)) { ERRX1(sess, "io_read_byte"); goto out; - } else if (0 == flag) + } else if (flag == 0) break; if (!flist_realloc(sess, &fl, &flsz, &flmax)) { @@ -555,7 +555,7 @@ goto out; } ff->st.mtime = ival; - } else if (NULL == fflast) { + } else if (fflast == NULL) { ERRX(sess, "same time without last entry"); goto out; } else @@ -569,7 +569,7 @@ goto out; } ff->st.mode = ival; - } else if (NULL == fflast) { + } else if (fflast == NULL) { ERRX(sess, "same mode without last entry"); goto out; } else @@ -582,12 +582,12 @@ if (!io_read_size(sess, fd, &lsz)) { ERRX1(sess, "io_read_size"); goto out; - } else if (0 == lsz) { + } else if (lsz == 0) { ERRX(sess, "empty link name"); goto out; } ff->link = calloc(lsz + 1, 1); - if (NULL == ff->link) { + if (ff->link == NULL) { ERR(sess, "calloc"); goto out; } @@ -647,7 +647,7 @@ * the non-recursive scan. */ - if (-1 == lstat(root, &st)) { + if (lstat(root, &st) == -1) { ERR(sess, "%s: lstat", root); return 0; } else if (S_ISREG(st.st_mode)) { @@ -656,12 +656,12 @@ return 0; } f = &(*fl)[(*sz) - 1]; - assert(NULL != f); + assert(f != NULL); if (!flist_append(sess, f, &st, root)) { ERRX1(sess, "flist_append"); return 0; - } else if (-1 == unveil(root, "r")) { + } else if (unveil(root, "r") == -1) { ERR(sess, "%s: unveil", root); return 0; } @@ -675,12 +675,12 @@ return 0; } f = &(*fl)[(*sz) - 1]; - assert(NULL != f); + assert(f != NULL); if (!flist_append(sess, f, &st, root)) { ERRX1(sess, "flist_append"); return 0; - } else if (-1 == unveil(root, "r")) { + } else if (unveil(root, "r") == -1) { ERR(sess, "%s: unveil", root); return 0; } @@ -698,7 +698,7 @@ stripdir = strlen(root); assert(stripdir > 0); - if ('/' != root[stripdir - 1]) + if (root[stripdir - 1] != '/') stripdir = 0; /* @@ -707,8 +707,8 @@ * last directory component. */ - if (0 == stripdir) - if (NULL != (cp = strrchr(root, '/'))) + if (stripdir == 0) + if ((cp = strrchr(root, '/')) != NULL) stripdir = cp - root + 1; /* @@ -718,13 +718,13 @@ * We'll make sense of it in flist_send. */ - if (NULL == (fts = fts_open(cargv, FTS_PHYSICAL, NULL))) { + if ((fts = fts_open(cargv, FTS_PHYSICAL, NULL)) == NULL) { ERR(sess, "fts_open"); return 0; } errno = 0; - while (NULL != (ent = fts_read(fts))) { + while ((ent = fts_read(fts)) != NULL) { if (!flist_fts_check(sess, ent)) { errno = 0; continue; @@ -732,7 +732,7 @@ /* We don't allow symlinks without -l. */ - assert(NULL != ent->fts_statp); + assert(ent->fts_statp != NULL); if (S_ISLNK(ent->fts_statp->st_mode) && !sess->opts->preserve_links) { WARNX(sess, "%s: skipping " @@ -758,7 +758,7 @@ goto out; } } else { - if (NULL == (f->path = strdup(ent->fts_path))) { + if ((f->path = strdup(ent->fts_path)) == NULL) { ERR(sess, "strdup"); goto out; } @@ -771,7 +771,7 @@ if (S_ISLNK(ent->fts_statp->st_mode)) { f->link = symlink_read(sess, f->path); - if (NULL == f->link) { + if (f->link == NULL) { ERRX1(sess, "symlink_read"); goto out; } @@ -783,7 +783,7 @@ if (errno) { ERR(sess, "fts_read"); goto out; - } else if (-1 == unveil(root, "r")) { + } else if (unveil(root, "r") == -1) { ERR(sess, "%s: unveil", root); goto out; } @@ -840,7 +840,7 @@ assert(argc); - if (NULL == (fl = calloc(argc, sizeof(struct flist)))) { + if ((fl = calloc(argc, sizeof(struct flist))) == NULL) { ERR(sess, "calloc"); return 0; } @@ -848,7 +848,7 @@ for (i = 0; i < argc; i++) { if ('\0' == argv[i][0]) continue; - if (-1 == lstat(argv[i], &st)) { + if (lstat(argv[i], &st) == -1) { ERR(sess, "%s: lstat", argv[i]); goto out; } @@ -876,11 +876,11 @@ f = &fl[flsz++]; - assert(NULL != f); + assert(f != NULL); /* Add this file to our file-system worldview. */ - if (-1 == unveil(argv[i], "r")) { + if (unveil(argv[i], "r") == -1) { ERR(sess, "%s: unveil", argv[i]); goto out; } else if (!flist_append(sess, f, &st, argv[i])) { @@ -921,7 +921,7 @@ /* After scanning, lock our file-system view. */ - if (-1 == unveil(NULL, NULL)) { + if (unveil(NULL, NULL) == -1) { ERR(sess, "unveil"); return 0; } else if (!rc) @@ -981,10 +981,10 @@ for (i = 0; i < wflsz; i++) if (FLSTAT_TOP_DIR & wfl[i].st.flags) cargvs++; - if (0 == cargvs) + if (cargvs == 0) return 1; - if (NULL == (cargv = calloc(cargvs + 1, sizeof(char *)))) { + if ((cargv = calloc(cargvs + 1, sizeof(char *))) == NULL) { ERR(sess, "calloc"); return 0; } @@ -996,8 +996,8 @@ * Otherwise, look through all top-levels. */ - if (wflsz && 0 == strcmp(wfl[0].wpath, ".")) { - assert(1 == cargvs); + if (wflsz && strcmp(wfl[0].wpath, ".") == 0) { + assert(cargvs == 1); assert(S_ISDIR(wfl[0].st.mode)); if (asprintf(&cargv[0], "%s/", root) < 0) { ERR(sess, "asprintf"); @@ -1011,8 +1011,7 @@ continue; assert(S_ISDIR(wfl[i].st.mode)); assert(strcmp(wfl[i].wpath, ".")); - c = asprintf(&cargv[j], - "%s/%s", root, wfl[i].wpath); + c = asprintf(&cargv[j], "%s/%s", root, wfl[i].wpath); if (c < 0) { ERR(sess, "asprintf"); cargv[j] = NULL; @@ -1044,11 +1043,11 @@ for (i = 0; i < wflsz; i++) { memset(&hent, 0, sizeof(ENTRY)); - if (NULL == (hent.key = strdup(wfl[i].wpath))) { + if ((hent.key = strdup(wfl[i].wpath)) == NULL) { ERR(sess, "strdup"); goto out; } - if (NULL == (hentp = hsearch(hent, ENTER))) { + if ((hentp = hsearch(hent, ENTER)) == NULL) { ERR(sess, "hsearch"); goto out; } else if (hentp->key != hent.key) { @@ -1064,15 +1063,15 @@ * If the directories don't exist, it's ok. */ - if (NULL == (fts = fts_open(cargv, FTS_PHYSICAL, NULL))) { + if ((fts = fts_open(cargv, FTS_PHYSICAL, NULL)) == NULL) { ERR(sess, "fts_open"); goto out; } stripdir = strlen(root) + 1; errno = 0; - while (NULL != (ent = fts_read(fts))) { - if (FTS_NS == ent->fts_info) + while ((ent = fts_read(fts)) != NULL) { + if (ent->fts_info == FTS_NS) continue; if (!flist_fts_check(sess, ent)) { errno = 0; @@ -1084,7 +1083,7 @@ memset(&hent, 0, sizeof(ENTRY)); hent.key = ent->fts_path + stripdir; - if (NULL != hsearch(hent, FIND)) + if (hsearch(hent, FIND) != NULL) continue; /* Not found: we'll delete it. */ @@ -1095,12 +1094,12 @@ } f = &(*fl)[*sz - 1]; - if (NULL == (f->path = strdup(ent->fts_path))) { + if ((f->path = strdup(ent->fts_path)) == NULL) { ERR(sess, "strdup"); goto out; } f->wpath = f->path + stripdir; - assert(NULL != ent->fts_statp); + assert(ent->fts_statp != NULL); flist_copy_stat(f, ent->fts_statp); errno = 0; } @@ -1113,7 +1112,7 @@ qsort(*fl, *sz, sizeof(struct flist), flist_cmp); rc = 1; out: - if (NULL != fts) + if (fts != NULL) fts_close(fts); for (i = 0; i < cargvs; i++) free(cargv[i]); @@ -1134,7 +1133,7 @@ ssize_t i; int flag; - if (0 == flsz) + if (flsz == 0) return 1; assert(sess->opts->del); @@ -1144,10 +1143,10 @@ LOG1(sess, "%s: deleting", fl[i].wpath); if (sess->opts->dry_run) continue; - assert(-1 != root); + assert(root != -1); flag = S_ISDIR(fl[i].st.mode) ? AT_REMOVEDIR : 0; - if (-1 == unlinkat(root, fl[i].wpath, flag) && - ENOENT != errno) { + if (unlinkat(root, fl[i].wpath, flag) == -1 && + errno != ENOENT) { ERR(sess, "%s: unlinkat", fl[i].wpath); return 0; }