Re: [HACKERS] pnstrdup considered armed and dangerous

2017-10-03 Thread Andres Freund
On 2016-10-03 14:55:24 -0700, Andres Freund wrote: > Hi, > > A colleage of me just wrote innocent looking code like > char *shardRelationName = pnstrdup(relationName, NAMEDATALEN); > which is at the moment wrong if relationName isn't preallocated to > NAMEDATALEN size. > > /* > *

Re: [HACKERS] pnstrdup considered armed and dangerous

2016-10-04 Thread Geoff Winkless
On 4 October 2016 at 14:12, Geoff Winkless wrote: > Well I wouldn't say it's wrong, exactly. It might produce a segfault > if relationName[NAMEDATALEN] is outside readable memory for the > process, but otherwise it will behave as defined. Finger slippage. Of course I meant

Re: [HACKERS] pnstrdup considered armed and dangerous

2016-10-04 Thread Geoff Winkless
On 3 October 2016 at 22:55, Andres Freund wrote: > A colleage of me just wrote innocent looking code like > char *shardRelationName = pnstrdup(relationName, NAMEDATALEN); > which is at the moment wrong if relationName isn't preallocated to > NAMEDATALEN size. [snip] >

Re: [HACKERS] pnstrdup considered armed and dangerous

2016-10-04 Thread Robert Haas
On Mon, Oct 3, 2016 at 5:55 PM, Andres Freund wrote: > /* > * pnstrdup > * Like pstrdup(), but append null byte to a > * not-necessarily-null-terminated input string. > */ > char * > pnstrdup(const char *in, Size len) > { > char *out

[HACKERS] pnstrdup considered armed and dangerous

2016-10-03 Thread Andres Freund
Hi, A colleage of me just wrote innocent looking code like char *shardRelationName = pnstrdup(relationName, NAMEDATALEN); which is at the moment wrong if relationName isn't preallocated to NAMEDATALEN size. /* * pnstrdup * Like pstrdup(), but append null byte to a *