Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace strncopy() with strlcpy() #639

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/lib/libast/include/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ extern int strngrpmatch(const char *, size_t, const char *, ssize_t *, int, int)
extern unsigned int strhash(const char *);
extern void *strlook(const void *, size_t, const char *);
extern int strmatch(const char *, const char *);
extern char *strncopy(char *, const char *, size_t);
extern int strnpcmp(const char *, const char *, size_t);
extern double strntod(const char *, size_t, char **);
extern _ast_fltmax_t strntold(const char *, size_t, char **);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/path/pathfind.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ char *pathfind(const char *name, const char *lib, const char *type, char *buf, s

if ((type && !*type) || (((s = strrchr(name, '/')) || (s = (char *)name)) && strchr(s, '.'))) {
if (regular(name, &st)) {
strncopy(buf, name, size);
strlcpy(buf, name, size);
return buf;
}
type = 0;
Expand Down
14 changes: 7 additions & 7 deletions src/lib/libast/path/pathprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ char *pathprobe_20100601(const char *lang, const char *tool, const char *aproc,
if (*proc != '/') {
p = strchr(proc, ' ');
if (p) {
strncopy(buf, proc, p - proc + 1);
strlcpy(buf, proc, p - proc + 1);
proc = buf;
}
if (!(proc = pathpath(proc, NULL, PATH_ABSOLUTE | PATH_REGULAR | PATH_EXECUTE, cmd,
sizeof(cmd)))) {
proc = (char *)aproc;
} else if (p) {
n = strlen(proc);
strncopy(proc + n, p, PATH_MAX - n - 1);
strlcpy(proc + n, p, PATH_MAX - n - 1);
}
}
if (!path) {
Expand All @@ -146,12 +146,12 @@ char *pathprobe_20100601(const char *lang, const char *tool, const char *aproc,
p = k + sfsprintf(k, x - k, "%s/%s/", lang, tool);
pathkey(lang, tool, proc, key, sizeof(key), attr, attrsize);
if (op >= -2) {
strncopy(p, key, x - p);
strlcpy(p, key, x - p);
if (pathpath(lib, "", PATH_ABSOLUTE, path, pathsize) && !stat(path, &st) &&
(st.st_mode & S_IWUSR))
return path == buf ? strdup(path) : path;
}
e = strncopy(p, probe, x - p);
e = p + strlcpy(p, probe, x - p);
if (!pathpath(lib, "", PATH_ABSOLUTE | PATH_EXECUTE, path, pathsize) || stat(path, &ps))
return 0;
for (;;) {
Expand All @@ -165,7 +165,7 @@ char *pathprobe_20100601(const char *lang, const char *tool, const char *aproc,
}
np = path + n - (e - k);
nx = path + PATH_MAX - 1;
strncopy(np, probe, nx - np);
strlcpy(np, probe, nx - np);
if (!stat(path, &st)) break;

/*
Expand All @@ -190,15 +190,15 @@ char *pathprobe_20100601(const char *lang, const char *tool, const char *aproc,
}
}
}
strncopy(p, key, x - p);
strlcpy(p, key, x - p);
p = np;
x = nx;
strcpy(exe, path);
if (op >= -1 && ((!(st.st_mode & S_ISUID) && ps.st_uid != geteuid()) || rofs(path))) {
if (!(p = getenv("HOME"))) return 0;
p = path + sfsprintf(path, PATH_MAX - 1, "%s/.%s/%s/", p, probe, HOSTTYPE);
}
strncopy(p, k, x - p);
strlcpy(p, k, x - p);
force = 0;
if (op >= 0 && !stat(path, &st)) {
if (ptime <= (unsigned long)st.st_mtime || ptime <= (unsigned long)st.st_ctime) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/string/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ libast_files += [
'string/strcopy.c', 'string/strelapsed.c', 'string/stresc.c',
'string/streval.c', 'string/strexpr.c', 'string/strgid.c',
'string/strlcat.c', 'string/strlcpy.c', 'string/strlook.c',
'string/strmatch.c', 'string/strncopy.c',
'string/strmatch.c',
'string/strnpcmp.c', 'string/strntod.c', 'string/strntol.c',
'string/strntold.c', 'string/strntoll.c', 'string/strnton.c',
'string/strntonll.c', 'string/strntoul.c', 'string/strntoull.c',
Expand Down
42 changes: 0 additions & 42 deletions src/lib/libast/string/strncopy.c

This file was deleted.