Simplify code with strlcpy/strlcat.

MFC after:	2 weeks
This commit is contained in:
Xin LI 2019-12-01 08:04:22 +00:00
parent 84474332d3
commit 76b71718fe
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=355260
2 changed files with 4 additions and 7 deletions

View File

@ -97,7 +97,6 @@ static int crmod, digit, lower, upper;
char hostname[MAXHOSTNAMELEN]; char hostname[MAXHOSTNAMELEN];
static char name[MAXLOGNAME*3]; static char name[MAXLOGNAME*3];
static char dev[] = _PATH_DEV;
static char ttyn[32]; static char ttyn[32];
#define OBUFSIZ 128 #define OBUFSIZ 128
@ -218,8 +217,8 @@ main(int argc, char *argv[])
if (argc <= 2 || strcmp(argv[2], "-") == 0) if (argc <= 2 || strcmp(argv[2], "-") == 0)
strcpy(ttyn, ttyname(STDIN_FILENO)); strcpy(ttyn, ttyname(STDIN_FILENO));
else { else {
strcpy(ttyn, dev); strcpy(ttyn, _PATH_DEV);
strncat(ttyn, argv[2], sizeof(ttyn)-sizeof(dev)); strlcat(ttyn, argv[2], sizeof(ttyn));
if (strcmp(argv[0], "+") != 0) { if (strcmp(argv[0], "+") != 0) {
chown(ttyn, 0, 0); chown(ttyn, 0, 0);
chmod(ttyn, 0600); chmod(ttyn, 0600);

View File

@ -89,10 +89,8 @@ gettable(const char *name, char *buf)
l = 2; l = 2;
else else
l = strlen(sp->value) + 1; l = strlen(sp->value) + 1;
if ((p = malloc(l)) != NULL) { if ((p = malloc(l)) != NULL)
strncpy(p, sp->value, l); strlcpy(p, sp->value, l);
p[l-1] = '\0';
}
/* /*
* replace, even if NULL, else we'll * replace, even if NULL, else we'll
* have problems with free()ing static mem * have problems with free()ing static mem