Skip to content

Commit d18c1d1

Browse files
committed
Truncate incoming username and database name to NAMEDATALEN-1 characters
so that we don't reject overlength names unnecessarily.
1 parent 72fa242 commit d18c1d1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/backend/postmaster/postmaster.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.207 2001/02/11 23:12:28 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.208 2001/02/20 01:34:40 tgl Exp $
1515
*
1616
* NOTES
1717
*
@@ -1123,6 +1123,14 @@ readStartupPacket(void *arg, PacketLen len, void *pkt)
11231123
if (port->database[0] == '\0')
11241124
StrNCpy(port->database, si->user, sizeof(port->database));
11251125

1126+
/* Truncate given database and user names to length of a Postgres name. */
1127+
/* This avoids lookup failures when overlength names are given. */
1128+
1129+
if ((int) sizeof(port->database) >= NAMEDATALEN)
1130+
port->database[NAMEDATALEN-1] = '\0';
1131+
if ((int) sizeof(port->user) >= NAMEDATALEN)
1132+
port->user[NAMEDATALEN-1] = '\0';
1133+
11261134
/* Check a user name was given. */
11271135

11281136
if (port->user[0] == '\0')

0 commit comments

Comments
 (0)