Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XHZT2-0001t7-Ea for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Aug 2014 14:23:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XHZT1-0006DL-VE for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Aug 2014 14:23:56 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XHZT0-0006BS-UJ for pgsql-hackers@postgresql.org; Wed, 13 Aug 2014 14:23:55 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XHZSw-00089I-8T for pgsql-hackers@postgresql.org; Wed, 13 Aug 2014 14:23:51 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id 455559844E; Wed, 13 Aug 2014 07:23:48 -0700 (PDT) Received: from EX13-CAS-009.vmware.com (EX13-CAS-009.vmware.com [10.113.191.61]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 3F4DEB12D8; Wed, 13 Aug 2014 07:23:48 -0700 (PDT) Received: from EX13-MBX-024.vmware.com (10.113.191.44) by EX13-MBX-006.vmware.com (10.113.191.26) with Microsoft SMTP Server (TLS) id 15.0.775.38; Wed, 13 Aug 2014 07:23:34 -0700 Received: from [192.168.1.90] (10.113.160.246) by EX13-MBX-024.vmware.com (10.113.191.44) with Microsoft SMTP Server (TLS) id 15.0.775.38; Wed, 13 Aug 2014 07:23:34 -0700 Message-ID: <53EB74E2.2070002@vmware.com> Date: Wed, 13 Aug 2014 17:23:30 +0300 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.5.0 MIME-Version: 1.0 To: Kevin Grittner , David Rowley , Noah Misch CC: Alvaro Herrera , Tomas Vondra , PostgreSQL-development Subject: Re: strncpy is not a safe version of strcpy References: <20131115150927.GA6220@eldon.alvh.no-ip.org> <20140813031918.GA286401@tornado.leadboat.com> <1407936691.21837.YahooMailNeo@web122301.mail.ne1.yahoo.com> In-Reply-To: <1407936691.21837.YahooMailNeo@web122301.mail.ne1.yahoo.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.113.160.246] X-ClientProxiedBy: EX13-CAS-013.vmware.com (10.113.191.65) To EX13-MBX-024.vmware.com (10.113.191.44) X-Pg-Spam-Score: -7.6 (-------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 08/13/2014 04:31 PM, Kevin Grittner wrote: > David Rowley wrote: > >> I had a quick look at the usages of strncpy in master tonight and >> I've really just picked out the obviously broken ones for now. >> The other ones, on first look, either look safe, or require some >> more analysis to see what's actually done with the string. >> >> Does anyone disagree with the 2 changes in the attached? > > I am concerned that failure to check for truncation could allow > deletion of unexpected files or directories. While this is > probably not as dangerous as *executing* unexpected files, it seems > potentially problematic. At the very least, a code comment > explaining why calling unlink on something which is not what > appears to be expected is not a problem there. > > Some might consider it overkill, but I tend to draw a pretty hard > line on deleting or executing random files, even if the odds seem > to be that the mangled name won't find a match. Granted, those > problems exist now, but without checking for truncation it seems to > me that we're just deleting *different* incorrect filenames, not > really fixing the problem. strlcpy is clearly better than strncpy here, but I wonder if we should have yet another string copying function that throws an error instead of truncating, if the buffer is too small. What you really want in these cases is a "path too long" error. - Heikki -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers