diff options
author | Xin LI <delphij@FreeBSD.org> | 2017-07-07 02:48:55 +0000 |
---|---|---|
committer | Xin LI <delphij@FreeBSD.org> | 2017-07-07 02:48:55 +0000 |
commit | 95595f99b9cfe957be920db3a90f98b013c9f168 (patch) | |
tree | 5670f383494929235b52d87e3584d6be7022dd88 | |
parent | 3ab05e867444f92b325e731a7ed59c9c7fb7b230 (diff) | |
download | src-95595f99b9cfe957be920db3a90f98b013c9f168.tar.gz src-95595f99b9cfe957be920db3a90f98b013c9f168.zip |
- Use strlcat() instead of strncat().
- Use asprintf() and handle allocation errors.
Reviewed by: kevlo
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D11486
Notes
Notes:
svn path=/head/; revision=320761
-rw-r--r-- | sbin/init/init.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/sbin/init/init.c b/sbin/init/init.c index cc7d8e5d2060..34e40457622f 100644 --- a/sbin/init/init.c +++ b/sbin/init/init.c @@ -1271,8 +1271,8 @@ new_session(session_t *sprev, struct ttyent *typ) sp->se_flags |= SE_PRESENT; - sp->se_device = malloc(sizeof(_PATH_DEV) + strlen(typ->ty_name)); - sprintf(sp->se_device, "%s%s", _PATH_DEV, typ->ty_name); + if (asprintf(&sp->se_device, "%s%s", _PATH_DEV, typ->ty_name) < 0) + err(1, "asprintf"); /* * Attempt to open the device, if we get "device not configured" @@ -1315,8 +1315,8 @@ setupargv(session_t *sp, struct ttyent *typ) free(sp->se_getty_argv_space); free(sp->se_getty_argv); } - sp->se_getty = malloc(strlen(typ->ty_getty) + strlen(typ->ty_name) + 2); - sprintf(sp->se_getty, "%s %s", typ->ty_getty, typ->ty_name); + if (asprintf(&sp->se_getty, "%s %s", typ->ty_getty, typ->ty_name) < 0) + err(1, "asprintf"); sp->se_getty_argv_space = strdup(sp->se_getty); sp->se_getty_argv = construct_argv(sp->se_getty_argv_space); if (sp->se_getty_argv == NULL) { @@ -1429,7 +1429,7 @@ start_window_system(session_t *sp) if (sp->se_type) { /* Don't use malloc after fork */ strcpy(term, "TERM="); - strncat(term, sp->se_type, sizeof(term) - 6); + strlcat(term, sp->se_type, sizeof(term)); env[0] = term; env[1] = 0; } @@ -1493,7 +1493,7 @@ start_getty(session_t *sp) if (sp->se_type) { /* Don't use malloc after fork */ strcpy(term, "TERM="); - strncat(term, sp->se_type, sizeof(term) - 6); + strlcat(term, sp->se_type, sizeof(term)); env[0] = term; env[1] = 0; } else |