From owner-svn-src-head@FreeBSD.ORG Sat May 9 23:44:39 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 675B6A8A; Sat, 9 May 2015 23:44:39 +0000 (UTC) Received: from mail-oi0-x22b.google.com (mail-oi0-x22b.google.com [IPv6:2607:f8b0:4003:c06::22b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 259EE123E; Sat, 9 May 2015 23:44:39 +0000 (UTC) Received: by oica37 with SMTP id a37so82217239oic.0; Sat, 09 May 2015 16:44:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :message-id:references:to; bh=8TpVqXjz2fPzRyXCd8V/noWDHkLx8esV1Yowa0Kv/Rk=; b=dCD90o4yPrAl1/lAoYydYnFDB0xOPQeRMgl+8avjMxupFOQPyxeh+v3I76zTyQ43Sp BT+Ay2Ft83Q2T+OLIKpiSfU8queQDQPN7QQAp9SuriZ1ymjVTjoKe8ML/3b3M+i+XSgA H148zScobwWfjgWSs9kcaq3KK+sWhhKymHMZCRtWFCP9iIw/KHA4A4SnOm5ksQGXKJeo 50/UZk6UwkteJGha8bHs2Tdw5Lcr3S3AYbTNa1dXUxytbFMcZ9P/IsN2gbF88qDOVhxQ siepiYTp/RaXuF6qIPg/OE89bYO34APRuXLlV/VscfU+nDwtgcGkFcKJbZQw/ACIMmN2 1m7A== X-Received: by 10.202.0.75 with SMTP id 72mr3095000oia.131.1431215078309; Sat, 09 May 2015 16:44:38 -0700 (PDT) Received: from ?IPv6:2601:8:ab80:7d6:c4cd:f4f:4d0d:e624? ([2601:8:ab80:7d6:c4cd:f4f:4d0d:e624]) by mx.google.com with ESMTPSA id y139sm6044023oia.17.2015.05.09.16.44.37 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 09 May 2015 16:44:37 -0700 (PDT) Subject: Re: svn commit: r282685 - head/usr.sbin/pw Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Content-Type: multipart/signed; boundary="Apple-Mail=_A265B449-880F-4493-8566-C147337A6B11"; protocol="application/pgp-signature"; micalg=pgp-sha512 X-Pgp-Agent: GPGMail 2.5b6 From: Garrett Cooper In-Reply-To: <20150509230349.GG54347@ivaldir.etoilebsd.net> Date: Sat, 9 May 2015 16:44:37 -0700 Cc: "svn-src-head@freebsd.org" , "svn-src-all@freebsd.org" , "src-committers@freebsd.org" Message-Id: <1F56EC53-9C20-42CC-BD60-186675F0CDB1@gmail.com> References: <201505091912.t49JCHRf067749@svn.freebsd.org> <4DE758E7-BE6B-45D6-A184-9443FB21F4A7@gmail.com> <20150509230349.GG54347@ivaldir.etoilebsd.net> To: Baptiste Daroussin X-Mailer: Apple Mail (2.1878.6) 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: Sat, 09 May 2015 23:44:39 -0000 --Apple-Mail=_A265B449-880F-4493-8566-C147337A6B11 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On May 9, 2015, at 16:03, Baptiste Daroussin wrote: > On Sat, May 09, 2015 at 03:54:09PM -0700, Garrett Cooper wrote: >>=20 >>> On May 9, 2015, at 12:12, Baptiste Daroussin = wrote: >>>=20 >>> Author: bapt >>> Date: Sat May 9 19:12:16 2015 >>> New Revision: 282685 >>> URL: https://svnweb.freebsd.org/changeset/base/282685 >>>=20 >>> Log: >>> Replace malloc(3) + strcpy(3) + strcat(3) by asprintf(3) >>>=20 >>> Modified: >>> head/usr.sbin/pw/pw_user.c >>>=20 >>> Modified: head/usr.sbin/pw/pw_user.c >>> = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D >>> --- head/usr.sbin/pw/pw_user.c Sat May 9 19:11:01 2015 = (r282684) >>> +++ head/usr.sbin/pw/pw_user.c Sat May 9 19:12:16 2015 = (r282685) >>> @@ -363,11 +363,9 @@ pw_user(struct userconf * cnf, int mode, >>> if (mode =3D=3D M_LOCK) { >>> if (strncmp(pwd->pw_passwd, locked_str, = sizeof(locked_str)-1) =3D=3D 0) >>> errx(EX_DATAERR, "user '%s' is already locked", = pwd->pw_name); >>> - passtmp =3D malloc(strlen(pwd->pw_passwd) + = sizeof(locked_str)); >>> + asprintf(&passtmp, "%s%s", locked_str, pwd->pw_passwd); >>> if (passtmp =3D=3D NULL) /* disaster */ >>> errx(EX_UNAVAILABLE, "out of memory"); >>> - strcpy(passtmp, locked_str); >>> - strcat(passtmp, pwd->pw_passwd); >>> pwd->pw_passwd =3D passtmp; >>> edited =3D 1; >>> } else if (mode =3D=3D M_UNLOCK) { >>=20 >> Please check the return values from asprintf.. >=20 > As said in the manpage: >=20 > If sufficient space cannot be allocated, asprintf() > and vasprintf() will return -1 and set ret to be a NULL pointer. >=20 > hence: > if (passtmp =3D=3D NULL) /* disaster */ > errx(EX_UNAVAILABLE, "out of memory"); >=20 > is checking properly asprintf return. >=20 > Am I missing something? Nope. Carry on! --Apple-Mail=_A265B449-880F-4493-8566-C147337A6B11 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQEcBAEBCgAGBQJVTpvmAAoJEMZr5QU6S73eaRsIAJF1/S9Tn96cEBD7j6OAEpTa d/jwAkB6yAG4Hlrp180yS5ykL/oXUqpRnC0ZFtXqPeEQ+EdEf7K41BcSbjm/P0uN SDIAbxPa0yX/gqkheeS1AOcm3a/4JnVS92kv8DqwSIQeNMpYQSduYhv1xXwRw1ri UPp2M7jTZrmevvFAC/6CLYgUIqGwMc233xedrPRMinQFe5RxmECUqYEg6PBmMVXg rZNF5bW0F1Q1qcVLX1aNrh7XQU6f6SD3Vky5Gppp+V7xUZID9AGFZIzY9qqXUg9F ae1eITB9MAzy+JyhiRrNRHuGN4otFKuRjGQiGffy6UqrtiQ5tFJQifzU4sMu06I= =f79m -----END PGP SIGNATURE----- --Apple-Mail=_A265B449-880F-4493-8566-C147337A6B11--