diff options
Diffstat (limited to 'coreconf/nsinstall/nsinstall.c')
-rw-r--r-- | coreconf/nsinstall/nsinstall.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/coreconf/nsinstall/nsinstall.c b/coreconf/nsinstall/nsinstall.c index 952c4e418..da5379759 100644 --- a/coreconf/nsinstall/nsinstall.c +++ b/coreconf/nsinstall/nsinstall.c @@ -84,8 +84,8 @@ mkdirs(char *path, mode_t mode) char * cp; int rv; struct stat sb; - - if (!path || !path[0]) + + if (!path || !path[0]) fail("Null pointer or empty string passed to mkdirs()"); while (*path == '/' && path[1] == '/') path++; @@ -103,7 +103,7 @@ mkdirs(char *path, mode_t mode) if (errno != EEXIST) fail("mkdirs cannot make %s", path); fprintf(stderr, "directory creation race: %s\n", path); - if (!stat(path, &sb) && S_ISDIR(sb.st_mode)) + if (!stat(path, &sb) && S_ISDIR(sb.st_mode)) rv = 0; } return rv; @@ -116,7 +116,7 @@ touid(char *owner) uid_t uid; char *cp; - if (!owner || !owner[0]) + if (!owner || !owner[0]) fail("Null pointer or empty string passed to touid()"); pw = getpwnam(owner); if (pw) @@ -134,7 +134,7 @@ togid(char *group) gid_t gid; char *cp; - if (!group || !group[0]) + if (!group || !group[0]) fail("Null pointer or empty string passed to togid()"); gr = getgrnam(group); if (gr) @@ -255,8 +255,9 @@ main(int argc, char **argv) len = strlen(name); base = xbasename(name); bnlen = strlen(base); - toname = (char*)xmalloc(tdlen + 1 + bnlen + 1); - sprintf(toname, "%s/%s", todir, base); + size_t toname_len = tdlen + 1 + bnlen + 1; + toname = (char*)xmalloc(toname_len); + snprintf(toname, toname_len, "%s/%s", todir, base); retry: exists = (lstat(toname, &tosb) == 0); @@ -270,7 +271,7 @@ retry: } if (!exists && mkdir(toname, mode) < 0) { /* we probably have two nsinstall programs in a race here. */ - if (errno == EEXIST && !stat(toname, &sb) && + if (errno == EEXIST && !stat(toname, &sb) && S_ISDIR(sb.st_mode)) { fprintf(stderr, "directory creation race: %s\n", toname); goto retry; @@ -288,7 +289,7 @@ retry: /* -L implies -l and prefixes names with a $cwd arg. */ len += lplen + 1; linkname = (char*)xmalloc(len + 1); - sprintf(linkname, "%s/%s", linkprefix, name); + snprintf(linkname, len+1, "%s/%s", linkprefix, name); } else if (dorelsymlink) { /* Symlink the relative path from todir to source name. */ linkname = (char*)xmalloc(PATH_MAX); @@ -344,7 +345,7 @@ retry: fromfd = open(name, O_RDONLY); if (fromfd < 0 || fstat(fromfd, &sb) < 0) fail("cannot access %s", name); - if (exists && + if (exists && (!S_ISREG(tosb.st_mode) || access(toname, W_OK) < 0)) { int rmrv; rmrv = (S_ISDIR(tosb.st_mode) ? rmdir : unlink)(toname); |