Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b534a56

Browse files
committed
Remove use of large BUFSIZ for buffers and use the proper struct sizes.
This greatly helps threaded libpq programs.
1 parent e1c8b37 commit b534a56

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

src/interfaces/libpq/fe-auth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.91 2004/08/29 04:13:12 momjian Exp $
13+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.92 2004/09/27 23:38:45 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -749,7 +749,7 @@ fe_getauthname(char *PQerrormsg)
749749
if (GetUserName(username, &namesize))
750750
name = username;
751751
#else
752-
char pwdbuf[BUFSIZ];
752+
char pwdbuf[sizeof(struct passwd)];
753753
struct passwd pwdstr;
754754
struct passwd *pw = NULL;
755755

src/interfaces/libpq/fe-secure.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.52 2004/09/26 22:51:49 tgl Exp $
14+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.53 2004/09/27 23:38:45 momjian Exp $
1515
*
1616
* NOTES
1717
* [ Most of these notes are wrong/obsolete, but perhaps not all ]
@@ -512,7 +512,7 @@ verify_peer(PGconn *conn)
512512

513513
{
514514
struct hostent hpstr;
515-
char buf[BUFSIZ];
515+
char buf[sizeof(struct hostent)];
516516
int herrno = 0;
517517

518518
/*
@@ -598,7 +598,7 @@ load_dh_file(int keylength)
598598
#ifdef WIN32
599599
return NULL;
600600
#else
601-
char pwdbuf[BUFSIZ];
601+
char pwdbuf[sizeof(struct passwd)];
602602
struct passwd pwdstr;
603603
struct passwd *pwd = NULL;
604604
FILE *fp;
@@ -745,7 +745,7 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
745745
#ifdef WIN32
746746
return 0;
747747
#else
748-
char pwdbuf[BUFSIZ];
748+
char pwdbuf[sizeof(struct passwd)];
749749
struct passwd pwdstr;
750750
struct passwd *pwd = NULL;
751751
struct stat buf,
@@ -952,7 +952,7 @@ initialize_SSL(PGconn *conn)
952952
{
953953
#ifndef WIN32
954954
struct stat buf;
955-
char pwdbuf[BUFSIZ];
955+
char pwdbuf[sizeof(struct passwd)];
956956
struct passwd pwdstr;
957957
struct passwd *pwd = NULL;
958958
char fnbuf[MAXPGPATH];

src/port/getaddrinfo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Copyright (c) 2003, PostgreSQL Global Development Group
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/port/getaddrinfo.c,v 1.13 2004/09/27 23:24:45 momjian Exp $
15+
* $PostgreSQL: pgsql/src/port/getaddrinfo.c,v 1.14 2004/09/27 23:39:14 momjian Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -85,7 +85,7 @@ getaddrinfo(const char *node, const char *service,
8585

8686
#ifdef FRONTEND
8787
struct hostent hpstr;
88-
char buf[BUFSIZ];
88+
char buf[sizeof(struct hostent)];
8989
int herrno = 0;
9090

9191
pqGethostbyname(node, &hpstr, buf, sizeof(buf),

src/port/thread.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
99
*
10-
* $PostgreSQL: pgsql/src/port/thread.c,v 1.26 2004/09/27 23:24:45 momjian Exp $
10+
* $PostgreSQL: pgsql/src/port/thread.c,v 1.27 2004/09/27 23:39:14 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -103,15 +103,13 @@ pqGetpwuid(uid_t uid, struct passwd * resultbuf, char *buffer,
103103
/* POSIX version */
104104
getpwuid_r(uid, resultbuf, buffer, buflen, result);
105105
#else
106-
107106
/*
108107
* Early POSIX draft of getpwuid_r() returns 'struct passwd *'.
109108
* getpwuid_r(uid, resultbuf, buffer, buflen)
110109
*/
111110
*result = getpwuid_r(uid, resultbuf, buffer, buflen);
112111
#endif
113112
#else
114-
115113
/* no getpwuid_r() available, just use getpwuid() */
116114
*result = getpwuid(uid);
117115
#endif

0 commit comments

Comments
 (0)