Re: pnstrdup considered armed and dangerous - Mailing list pgsql-hackers

From Geoff Winkless
Subject Re: pnstrdup considered armed and dangerous
Date
Msg-id CAEzk6ffQGGykqNdR-fcGi9grj0=m6QXVV7CqM2i6N5XGZTHCAA@mail.gmail.com
Whole thread Raw
In response to pnstrdup considered armed and dangerous  (Andres Freund <andres@anarazel.de>)
Responses Re: pnstrdup considered armed and dangerous  (Geoff Winkless <pgsqladmin@geoff.dj>)
List pgsql-hackers
On 3 October 2016 at 22:55, Andres Freund <andres@anarazel.de> 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]
> isn't that a somewhat weird behaviour / implementation? Not really like
> strndup(), which one might believe to be analoguous...

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.

Geoff



pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: Transactions involving multiple postgres foreign servers
Next
From: Geoff Winkless
Date:
Subject: Re: pnstrdup considered armed and dangerous