From owner-svn-src-head@freebsd.org Fri Jul 7 02:48:56 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3A82BD98004; Fri, 7 Jul 2017 02:48:56 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 09B5664192; Fri, 7 Jul 2017 02:48:55 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v672mtY5048241; Fri, 7 Jul 2017 02:48:55 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v672mtJV048240; Fri, 7 Jul 2017 02:48:55 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201707070248.v672mtJV048240@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Fri, 7 Jul 2017 02:48:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r320761 - head/sbin/init X-SVN-Group: head X-SVN-Commit-Author: delphij X-SVN-Commit-Paths: head/sbin/init X-SVN-Commit-Revision: 320761 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jul 2017 02:48:56 -0000 Author: delphij Date: Fri Jul 7 02:48:55 2017 New Revision: 320761 URL: https://svnweb.freebsd.org/changeset/base/320761 Log: - 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 Modified: head/sbin/init/init.c Modified: head/sbin/init/init.c ============================================================================== --- head/sbin/init/init.c Fri Jul 7 00:34:51 2017 (r320760) +++ head/sbin/init/init.c Fri Jul 7 02:48:55 2017 (r320761) @@ -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