Skip to content

Commit 8090616

Browse files
committed
Use StrNCpy not strncpy to fill hash key, to ensure the resulting key
is null-terminated. I think this is not a real bug because the parser would always have truncated the identifier to NAMEDATALEN-1 already, but let's be safe. Per report from Klocwork.
1 parent 2ee3a72 commit 8090616

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/backend/commands/prepare.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2002-2004, PostgreSQL Global Development Group
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.33 2004/10/25 00:46:40 neilc Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.34 2004/12/03 21:26:31 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -296,8 +296,7 @@ StorePreparedStatement(const char *stmt_name,
296296

297297
/* Check for pre-existing entry of same name */
298298
/* See notes in FetchPreparedStatement */
299-
MemSet(key, 0, sizeof(key));
300-
strncpy(key, stmt_name, sizeof(key));
299+
StrNCpy(key, stmt_name, sizeof(key));
301300

302301
hash_search(prepared_queries, key, HASH_FIND, &found);
303302

@@ -370,8 +369,7 @@ FetchPreparedStatement(const char *stmt_name, bool throwError)
370369
* the hash package is picky enough that it needs to be
371370
* NULL-padded out to the appropriate length to work correctly.
372371
*/
373-
MemSet(key, 0, sizeof(key));
374-
strncpy(key, stmt_name, sizeof(key));
372+
StrNCpy(key, stmt_name, sizeof(key));
375373

376374
entry = (PreparedStatement *) hash_search(prepared_queries,
377375
key,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy