Re: Coding note: truncating with strlcpy() is not such a hot idea

From: Noah Misch <noah(at)leadboat(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Coding note: truncating with strlcpy() is not such a hot idea
Date: 2015-12-22 06:53:48
Message-ID: 20151222065348.GA2556345@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Dec 21, 2015 at 03:47:56PM -0500, Tom Lane wrote:
> 1. Using strlcpy to copy from sources that are not known null-terminated
> is outright unsafe: someday, you'll fall off the end of memory and
> SIGSEGV.
>
> 2. Even with a known null-terminated string, using strlcpy to chop small
> pieces out of it is not bright, because each call will traverse all the
> rest of the input. This means for example that extracting N words out
> of a long string will spend O(N^2) time in strlcpy.

Good points.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2015-12-22 06:56:04 Re: WIP: Fix parallel workers connection bug in pg_dump (Bug #13727)
Previous Message Amit Langote 2015-12-22 06:52:40 Re: Foreign join pushdown vs EvalPlanQual