summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2017-08-02 05:47:26 +0000
committerdelphij <delphij@FreeBSD.org>2017-08-02 05:47:26 +0000
commitd3396c4d0b4c8b9ae2c4f2487694eafd5e6a264c (patch)
treed202be4b08e27202ef5f14bd6128e461bec5cb20
parent4db040510220f7140eebd7064c5ecf7e8aca3384 (diff)
downloadFreeBSD-src-d3396c4d0b4c8b9ae2c4f2487694eafd5e6a264c.zip
FreeBSD-src-d3396c4d0b4c8b9ae2c4f2487694eafd5e6a264c.tar.gz
MFC r320761:
- Use strlcat() instead of strncat(). - Use asprintf() and handle allocation errors.
-rw-r--r--sbin/init/init.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/sbin/init/init.c b/sbin/init/init.c
index 7c571d5..14f3288 100644
--- a/sbin/init/init.c
+++ b/sbin/init/init.c
@@ -1278,8 +1278,8 @@ new_session(session_t *sprev, int session_index, struct ttyent *typ)
sp->se_index = session_index;
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"
@@ -1322,8 +1322,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 == 0) {
@@ -1437,7 +1437,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;
}
@@ -1501,7 +1501,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
OpenPOWER on IntegriCloud