From owner-svn-src-head@FreeBSD.ORG Sun May 10 10:02:09 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EAD5C950; Sun, 10 May 2015 10:02:09 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 D90781A1D; Sun, 10 May 2015 10:02:09 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t4AA29SI031422; Sun, 10 May 2015 10:02:09 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t4AA29vb031421; Sun, 10 May 2015 10:02:09 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201505101002.t4AA29vb031421@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Sun, 10 May 2015 10:02:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r282718 - head/usr.sbin/pw X-SVN-Group: head 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.20 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: Sun, 10 May 2015 10:02:10 -0000 Author: bapt Date: Sun May 10 10:02:09 2015 New Revision: 282718 URL: https://svnweb.freebsd.org/changeset/base/282718 Log: Use strndup(3) instead of malloc(3) + memcpy(3) Check the return of strndup Modified: head/usr.sbin/pw/pw_conf.c Modified: head/usr.sbin/pw/pw_conf.c ============================================================================== --- head/usr.sbin/pw/pw_conf.c Sun May 10 09:37:54 2015 (r282717) +++ head/usr.sbin/pw/pw_conf.c Sun May 10 10:02:09 2015 (r282718) @@ -34,6 +34,7 @@ static const char rcsid[] = #include #include #include +#include #include "pw.h" @@ -211,15 +212,18 @@ boolean_str(int val) char * newstr(char const * p) { - char *q = NULL; + char *q; + size_t l; - if ((p = unquote(p)) != NULL) { - int l = strlen(p) + 1; + if ((p = unquote(p)) == NULL) + return (NULL); - if ((q = malloc(l)) != NULL) - memcpy(q, p, l); - } - return q; + l = strlen(p) + 1; + + if ((q = strndup(p, l)) == NULL) + err(1, "strndup()"); + + return (q); } struct userconf *