StrNCpy

From: "Maurice Gittens" <mgittens(at)gits(dot)nl>
To: <hackers(at)postgreSQL(dot)org>
Subject: StrNCpy
Date: 1998-03-31 09:12:07
Message-ID: 006201bd5c85$145d3360$fcf3b2c2@caleb..gits.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Boersenspielteam 1998-03-31 12:30:35 Re: [HACKERS] Reminder: Indices are not used
Previous Message Goran Thyni 1998-03-31 08:56:03 free-text searching