svn commit: r321907 - stable/10/sbin/init
Xin LI
delphij at FreeBSD.org
Wed Aug 2 05:47:27 UTC 2017
Author: delphij
Date: Wed Aug 2 05:47:26 2017
New Revision: 321907
URL: https://svnweb.freebsd.org/changeset/base/321907
Log:
MFC r320761:
- Use strlcat() instead of strncat().
- Use asprintf() and handle allocation errors.
Modified:
stable/10/sbin/init/init.c
Directory Properties:
stable/10/ (props changed)
Modified: stable/10/sbin/init/init.c
==============================================================================
--- stable/10/sbin/init/init.c Wed Aug 2 05:30:41 2017 (r321906)
+++ stable/10/sbin/init/init.c Wed Aug 2 05:47:26 2017 (r321907)
@@ -1278,8 +1278,8 @@ new_session(session_t *sprev, int session_index, struc
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
More information about the svn-src-stable
mailing list