Use strlcpy(3) to replace the idiomatic
strncpy(d, s, l); d[l - 1] = '\0'; statements.
This commit is contained in:
parent
d33ccadc81
commit
b8938b667e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=130633
@ -234,8 +234,8 @@ parse_date(time_t dt, char const * str)
|
||||
* Skip past any weekday prefix
|
||||
*/
|
||||
weekday(&str);
|
||||
str = strncpy(tmp, str, sizeof tmp - 1);
|
||||
tmp[sizeof tmp - 1] = '\0';
|
||||
strlcpy(tmp, str, sizeof(tmp));
|
||||
str = tmp;
|
||||
T = localtime(&dt);
|
||||
|
||||
/*
|
||||
@ -275,19 +275,15 @@ parse_date(time_t dt, char const * str)
|
||||
if ((q = strpbrk(p, " \t")) != NULL) { /* Time first? */
|
||||
int l = q - str;
|
||||
|
||||
strncpy(timestr, str, l);
|
||||
timestr[l] = '\0';
|
||||
strncpy(datestr, q + 1, sizeof datestr);
|
||||
datestr[sizeof datestr - 1] = '\0';
|
||||
strlcpy(timestr, str, l + 1);
|
||||
strlcpy(datestr, q + 1, sizeof(datestr));
|
||||
parse_time(timestr, &T->tm_hour, &T->tm_min, &T->tm_sec);
|
||||
parse_datesub(datestr, &T->tm_mday, &T->tm_mon, &T->tm_year);
|
||||
} else if ((q = strrchr(tmp, ' ')) != NULL) { /* Time last */
|
||||
int l = q - tmp;
|
||||
|
||||
strncpy(timestr, q + 1, sizeof timestr);
|
||||
timestr[sizeof timestr - 1] = '\0';
|
||||
strncpy(datestr, tmp, l);
|
||||
datestr[l] = '\0';
|
||||
strlcpy(timestr, q + 1, sizeof(timestr));
|
||||
strlcpy(datestr, tmp, l + 1);
|
||||
} else /* Bail out */
|
||||
return dt;
|
||||
parse_time(timestr, &T->tm_hour, &T->tm_min, &T->tm_sec);
|
||||
|
@ -187,8 +187,8 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
|
||||
}
|
||||
/* If this falls, fall back to old method */
|
||||
}
|
||||
p = strncpy(dbuf, cnf->home, sizeof dbuf);
|
||||
dbuf[MAXPATHLEN-1] = '\0';
|
||||
strlcpy(dbuf, cnf->home, sizeof(dbuf));
|
||||
p = dbuf;
|
||||
if (stat(dbuf, &st) == -1) {
|
||||
while ((p = strchr(++p, '/')) != NULL) {
|
||||
*p = '\0';
|
||||
@ -396,8 +396,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
|
||||
* invalidated by deletion
|
||||
*/
|
||||
sprintf(file, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
|
||||
strncpy(home, pwd->pw_dir, sizeof home);
|
||||
home[sizeof home - 1] = '\0';
|
||||
strlcpy(home, pwd->pw_dir, sizeof(home));
|
||||
|
||||
rc = delpwent(pwd);
|
||||
if (rc == -1)
|
||||
@ -978,8 +977,7 @@ shell_path(char const * path, char *shells[], char *sh)
|
||||
/*
|
||||
* We need to search paths
|
||||
*/
|
||||
strncpy(paths, path, sizeof paths);
|
||||
paths[sizeof paths - 1] = '\0';
|
||||
strlcpy(paths, path, sizeof(paths));
|
||||
for (p = strtok(paths, ": \t\r\n"); p != NULL; p = strtok(NULL, ": \t\r\n")) {
|
||||
int i;
|
||||
static char shellpath[256];
|
||||
@ -1118,8 +1116,7 @@ pw_password(struct userconf * cnf, struct cargs * args, char const * user)
|
||||
return "*";
|
||||
|
||||
case 1: /* user's name */
|
||||
strncpy(pwbuf, user, sizeof pwbuf);
|
||||
pwbuf[sizeof pwbuf - 1] = '\0';
|
||||
strlcpy(pwbuf, user, sizeof(pwbuf));
|
||||
break;
|
||||
}
|
||||
return pw_pwcrypt(pwbuf);
|
||||
@ -1144,17 +1141,14 @@ print_user(struct passwd * pwd, int pretty, int v7)
|
||||
struct tm * tptr;
|
||||
|
||||
if ((p = strtok(pwd->pw_gecos, ",")) != NULL) {
|
||||
strncpy(uname, p, sizeof uname);
|
||||
uname[sizeof uname - 1] = '\0';
|
||||
strlcpy(uname, p, sizeof(uname));
|
||||
if ((p = strtok(NULL, ",")) != NULL) {
|
||||
strncpy(office, p, sizeof office);
|
||||
office[sizeof office - 1] = '\0';
|
||||
strlcpy(office, p, sizeof(office));
|
||||
if ((p = strtok(NULL, ",")) != NULL) {
|
||||
strncpy(wphone, p, sizeof wphone);
|
||||
wphone[sizeof wphone - 1] = '\0';
|
||||
strlcpy(wphone, p, sizeof(wphone));
|
||||
if ((p = strtok(NULL, "")) != NULL) {
|
||||
strncpy(hphone, p, sizeof hphone);
|
||||
hphone[sizeof hphone - 1] = '\0';
|
||||
strlcpy(hphone, p,
|
||||
sizeof(hphone));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,8 +60,7 @@ vnextpwent(char const * nam, uid_t uid, int doclose)
|
||||
struct passwd * pw = NULL;
|
||||
static char pwtmp[1024];
|
||||
|
||||
strncpy(pwtmp, getpwpath(_MASTERPASSWD), sizeof pwtmp);
|
||||
pwtmp[sizeof pwtmp - 1] = '\0';
|
||||
strlcpy(pwtmp, getpwpath(_MASTERPASSWD), sizeof(pwtmp));
|
||||
|
||||
if (pwd_fp != NULL || (pwd_fp = fopen(pwtmp, "r")) != NULL) {
|
||||
int done = 0;
|
||||
@ -210,8 +209,7 @@ vnextgrent(char const * nam, gid_t gid, int doclose)
|
||||
static int memlen = 0;
|
||||
|
||||
extendline(&grtmp, &grlen, MAXPATHLEN);
|
||||
strncpy(grtmp, getgrpath(_GROUP), MAXPATHLEN);
|
||||
grtmp[MAXPATHLEN - 1] = '\0';
|
||||
strlcpy(grtmp, getgrpath(_GROUP), MAXPATHLEN);
|
||||
|
||||
if (grp_fp != NULL || (grp_fp = fopen(grtmp, "r")) != NULL) {
|
||||
int done = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user