StrNCpy - Mailing list pgsql-hackers

From Maurice Gittens
Subject StrNCpy
Date
Msg-id 006201bd5c85$145d3360$fcf3b2c2@caleb..gits.nl
Whole thread Raw
Responses Re: [HACKERS] StrNCpy  (Bruce Momjian <maillist@candle.pha.pa.us>)
List pgsql-hackers
Hi,

While debugging yet another overrun I came across the StrNCpy macro.
A quick grep of the source tells me that usage of the StrNCpy macro is
seemingly inconsistent.

Usage 1:
strptr = palloc(len);    // done is a diffrent context
ptr = palloc(len + 1);
StrNCpy(ptr, strptr, len + 1);

Usage 2:
NameData name;
StrNCpy(name.data, ptr2name, NAMEDATALEN);

The StrNCpy macro zero terminates the destination buffer.

Usage 1 is gives a read=buffer overrun (which I agree is not the most
serious of bugs
if you system doesn't dump core on it).
Usage 2 makes gives the name a maximum of 31 instead of 32 characters.

Is the maximun name length supposted to be 31 or 32 characters?

With regards from Maurice.


pgsql-hackers by date:

Previous
From: Goran Thyni
Date:
Subject: free-text searching
Next
From: "Boersenspielteam"
Date:
Subject: Re: [HACKERS] Reminder: Indices are not used