summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Drehmel <robert@FreeBSD.org>2004-06-17 14:07:16 +0000
committerRobert Drehmel <robert@FreeBSD.org>2004-06-17 14:07:16 +0000
commit517bc45d044a80a60c7264a22085496d99ab7c44 (patch)
tree4c4ad9807feaa64a6a4bf61486a662e587fb4d52
parent2baa9d6a4c21ebe8620f6512f672296828844b48 (diff)
downloadpw-darwin-517bc45d044a80a60c7264a22085496d99ab7c44.tar.gz
pw-darwin-517bc45d044a80a60c7264a22085496d99ab7c44.tar.zst
pw-darwin-517bc45d044a80a60c7264a22085496d99ab7c44.zip
Use strlcpy(3) to replace the idiomatic
strncpy(d, s, l); d[l - 1] = '\0'; statements.
-rw-r--r--pw/psdate.c16
-rw-r--r--pw/pw_user.c26
-rw-r--r--pw/pw_vpw.c6
3 files changed, 18 insertions, 30 deletions
diff --git a/pw/psdate.c b/pw/psdate.c
index f97253b..3f4c010 100644
--- a/pw/psdate.c
+++ b/pw/psdate.c
@@ -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);
diff --git a/pw/pw_user.c b/pw/pw_user.c
index f7a6c56..5fd3671 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -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));
}
}
}
diff --git a/pw/pw_vpw.c b/pw/pw_vpw.c
index bc5713e..473cbb6 100644
--- a/pw/pw_vpw.c
+++ b/pw/pw_vpw.c
@@ -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;