From owner-svn-src-all@freebsd.org Sat Jan 26 22:02:32 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6C39014B02AF for ; Sat, 26 Jan 2019 22:02:32 +0000 (UTC) (envelope-from 010001688c2cfbc4-d34e12a0-c113-4f96-8853-1543ea0b04cb-000000@amazonses.com) Received: from a8-52.smtp-out.amazonses.com (a8-52.smtp-out.amazonses.com [54.240.8.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 107826F83D for ; Sat, 26 Jan 2019 22:02:31 +0000 (UTC) (envelope-from 010001688c2cfbc4-d34e12a0-c113-4f96-8853-1543ea0b04cb-000000@amazonses.com) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=dqtolf56kk3wpt62c3jnwboqvr7iedax; d=tarsnap.com; t=1548539984; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=IyONnK3KcNDAb/NMkPxFDPeRpbXHOzoujmuqOvon/xs=; b=GJIkpvQOSSzNw3jtYJioUFypjdjMSaNHQtM2wCLCLz9FGKIjIZWVo2VFJcaN4Oon VaT9MdLevms3TOLsU3ZvAPUBa5TfFq/S3+7/ERMJI1gkmABECZhkIprV4+MQmwgH3DA w0twxXdnpv9c/877F/6RFA8a/+zEz/4sbsYuQnQQ= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1548539984; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding:Feedback-ID; bh=IyONnK3KcNDAb/NMkPxFDPeRpbXHOzoujmuqOvon/xs=; b=aeyhvh1uUySxNT1LCH8gkdNBrNE6+4TKgr1FiqK7upGAqXKo5DUlkQz1/k466LuG WE2jlE7v/HYCYjpjfH6Uu2llbxUrfv+4J6bD5tdEdAyu6g23eKnwT3sOKlNy8lCRhMQ f4KCairqYY6AzGOzMeEhp/9LQFI3V5FaP5oPV8/0= Subject: Re: svn commit: r343480 - head/lib/libfigpar To: rgrimes@freebsd.org, Stefan Esser Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org References: <201901262136.x0QLaAJv095518@pdx.rh.CN85.dnsmgr.net> From: Colin Percival Openpgp: preference=signencrypt Autocrypt: addr=cperciva@tarsnap.com; prefer-encrypt=mutual; keydata= mQGhBElrAAcRBACDfDys4ZtK+ErCJ1HAzYeteKpm3OEsvT/49AjUTLihkF79HhIKrCQU+1KC zv7BwHCMLb6hq30As9L7iFKG7n5QFLFC4Te/VcITUnWHMG/c3ViLOfJGvi+9/nOEHaM1dVJY D6tEp5yM1nHmVQpo9932j4KGuGFR0LhOK5IHXOSfGwCgxSFDPdgxe2OEjWxjGgY+oV3EafcD +JROXCTjlcQiG/OguQH4Vks3mhHfFnEppLxTkDuYgHZQiUtpcT9ssH5khgqoTyMar05OUdAj ZIhNbWDh4LgTj+7ZmvLhXT5Zxw8LX9d7T36aTB8XDQSenDqEtinMWOb0TCBBLbsB8EFG1WTT ESbZci9jJS5yhtktuZoY/eM8uXMD/3k4FWFO80VRRkELSp+XSy/VlSQjyi/rhl2nQq/oOA9F oJbDaB0yq9VNhxP+uFBzBWSqeIX0t1ZWLtNfVFr4TRP5hihI5ICrg/0OpqgisKsU2NFe9xyO hyJLYmfD8ebpDJ/9k30C7Iju9pVrwLm1QgS4S2fqJRcR+U4WbjvP7CgStCVDb2xpbiBQZXJj aXZhbCA8Y3BlcmNpdmFAdGFyc25hcC5jb20+iGEEExECACEFAklrALYCGwMHCwkIBwMCAQQV AggDBBYCAwECHgECF4AACgkQOM7KaQxqam6/igCgn+z2k3V5ggNppmWrZstt1U2lugsAoL7L wS9V9yLtil3oWmHtwpUqYruEuQINBElrAAcQCAD3ZLMIsP4CIDoJORg+YY0lqLVBgcnF7pFb 4Uy2+KvdWofN+DKH61rZLjgXXkNE9M4EQC1B4lGttBP8IY2gs41y3AUogGdyFbidq99rCBz7 LTsgARHwFxZoaHmXyiZLEU1QZuMqwPZV1mCviRhN5E3rRqYNXVcrnXAAuhBpvNyj/ntHvcDN 2/m+ochiuBYueU4kX3lHya7sOj+mTsndcWmQ9soOUyr8O0r/BG088bMn4qqtUw4dl5/pglXk jbl7uOOPinKf0WVd2r6M0wLPJCD4NPHrCWRLLLAjwfjrtoSRvXxDbXhCdgGBa72+K8eYLzVs hgq7tJOoBWzjVK6XRxR7AAMGB/9Mo3iJ2DxqDecd02KCB5BsFDICbJGhPltU7FwrtbC7djSb XUrwsEVLHi4st4cbdGNCWCrp0BRezXZKohKnNAPFOTK++ZfgeKxrV2sJod+Q9RILF86tQ4XF 7A7Yme5hy92t/WgiU4vc/fWbgP8gV/19f8nunaT2E9NSa70mZFjZNu4iuwThoUUO5CV3Wo0Y UISsnRK8XD1+LR3A2qVyLiFRwh/miC1hgLFCTGCQ3GLxZeZzIpYSlGdQJ0L5lixW5ZQD9r1I 8i/8zhE6qRFAM0upUMI3Gt1Oq2w03DiXrZU0Fu/R8Rm8rlnkQKA+95mRTUq1xL5P5NZIi4gJ Z569OPMFiEkEGBECAAkFAklrAAcCGwwACgkQOM7KaQxqam41igCfbaldnFTu5uAdrnrghESv EI3CAo8AoLkNMks1pThl2BJNRm4CtTK9xZeH Message-ID: <010001688c2cfbc4-d34e12a0-c113-4f96-8853-1543ea0b04cb-000000@email.amazonses.com> Date: Sat, 26 Jan 2019 21:59:44 +0000 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <201901262136.x0QLaAJv095518@pdx.rh.CN85.dnsmgr.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-SES-Outgoing: 2019.01.26-54.240.8.52 Feedback-ID: 1.us-east-1.Lv9FVjaNvvR5llaqfLoOVbo2VxOELl7cjN0AOyXnPlk=:AmazonSES X-Rspamd-Queue-Id: 107826F83D X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.99 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.99)[-0.991,0]; REPLY(-4.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Jan 2019 22:02:32 -0000 On 1/26/19 1:36 PM, Rodney W. Grimes wrote: >> Author: se >> Date: Sat Jan 26 21:30:26 2019 >> New Revision: 343480 >> URL: https://svnweb.freebsd.org/changeset/base/343480 >> >> Log: >> Silence Clang Scan warning about potentially unsafe use of strcpy. >> >> While this is a false positive, the use of strdup() simplifies the code. > > Though that might be true, it also has to recalculate the > length of the string which was already known by slen. > > I am not sure how often this code is called, > but that is wasted cycles in a library. The length of the string was already being recalculated, by strcpy. It seems to me that this could be written as temp = malloc(slen + 1); if (temp == NULL) /* could not allocate memory */ return (-1); memcpy(temp, source, slen + 1); which avoids both recalculating the string length and using strcpy? >> Modified: head/lib/libfigpar/string_m.c >> ============================================================================== >> --- head/lib/libfigpar/string_m.c Sat Jan 26 20:43:28 2019 (r343479) >> +++ head/lib/libfigpar/string_m.c Sat Jan 26 21:30:26 2019 (r343480) >> @@ -119,10 +119,9 @@ replaceall(char *source, const char *find, const char >> >> /* If replace is longer than find, we'll need to create a temp copy */ >> if (rlen > flen) { >> - temp = malloc(slen + 1); >> - if (errno != 0) /* could not allocate memory */ >> + temp = strdup(source); >> + if (temp == NULL) /* could not allocate memory */ >> return (-1); >> - strcpy(temp, source); >> } else >> temp = source; -- Colin Percival Security Officer Emeritus, FreeBSD | The power to serve Founder, Tarsnap | www.tarsnap.com | Online backups for the truly paranoid