summaryrefslogtreecommitdiff
path: root/coreconf
diff options
context:
space:
mode:
Diffstat (limited to 'coreconf')
-rw-r--r--coreconf/nsinstall/nsinstall.c21
-rw-r--r--coreconf/nsinstall/pathsub.c12
2 files changed, 17 insertions, 16 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);
diff --git a/coreconf/nsinstall/pathsub.c b/coreconf/nsinstall/pathsub.c
index c31a946f0..95fa67912 100644
--- a/coreconf/nsinstall/pathsub.c
+++ b/coreconf/nsinstall/pathsub.c
@@ -48,7 +48,7 @@ fail(char *format, ...)
fprintf(stderr, ": %s", strerror(errno));
#endif
}
-
+
putc('\n', stderr);
abort();
exit(1);
@@ -123,7 +123,7 @@ xmalloc(size_t size)
char *
xstrdup(char *s)
{
- if (!s || !s[0])
+ if (!s || !s[0])
fail("Null pointer or empty string passed to xstrdup()");
return strcpy((char*)xmalloc(strlen(s) + 1), s);
}
@@ -133,7 +133,7 @@ xbasename(char *path)
{
char *cp;
- if (!path || !path[0])
+ if (!path || !path[0])
fail("Null pointer or empty string passed to xbasename()");
while ((cp = strrchr(path, '/')) && cp[1] == '\0')
*cp = '\0';
@@ -144,7 +144,7 @@ xbasename(char *path)
void
xchdir(char *dir)
{
- if (!dir || !dir[0])
+ if (!dir || !dir[0])
fail("Null pointer or empty string passed to xchdir()");
if (chdir(dir) < 0)
fail("cannot change directory to %s", dir);
@@ -181,7 +181,7 @@ relatepaths(char *from, char *to, char *outpath)
len += 3;
}
while ((cp = getcomponent(cp, buf)) != 0) {
- sprintf(outpath + len, "%s/", buf);
+ snprintf(outpath + len, PATH_MAX - len, "%s/", buf);
len += strlen(outpath + len);
}
}
@@ -228,7 +228,7 @@ diagnosePath(const char * path)
struct stat sb;
char buf[BUFSIZ];
- if (!path || !path[0])
+ if (!path || !path[0])
fail("Null pointer or empty string passed to mkdirs()");
myPath = strdup(path);
if (!myPath)