Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9e0e148

Browse files
committed
pq_getstr didn't handle buffer overrun correctly; it would
fail to consume the rest of the input string, and worse it would writeone more byte than it should into the buffer, probably resulting in coredump.Fortunately there's a correct implementation next door in pqcomprim.c.
1 parente50feea commit9e0e148

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

‎src/backend/libpq/pqcomm.c

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.57 1998/10/13 20:44:40 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.58 1998/11/29 01:47:42 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -108,6 +108,9 @@ pq_init(int fd)
108108
*
109109
* used for debugging libpq
110110
*/
111+
112+
#if0/* not used anymore */
113+
111114
staticint
112115
pq_getc(FILE*fin)
113116
{
@@ -119,6 +122,8 @@ pq_getc(FILE *fin)
119122
returnc;
120123
}
121124

125+
#endif
126+
122127
/* --------------------------------
123128
*pq_gettty - return the name of the tty in the given buffer
124129
* --------------------------------
@@ -181,15 +186,9 @@ pq_flush()
181186
int
182187
pq_getstr(char*s,intmaxlen)
183188
{
184-
intc='\0';
185-
189+
intc;
186190
#ifdefMULTIBYTE
187-
unsignedchar*p,
188-
*ps;
189-
intlen;
190-
191-
ps=s;
192-
len=maxlen;
191+
char*p;
193192
#endif
194193

195194
if (Pfin== (FILE*)NULL)
@@ -198,27 +197,15 @@ pq_getstr(char *s, int maxlen)
198197
returnEOF;
199198
}
200199

201-
while (maxlen--&& (c=pq_getc(Pfin))!=EOF&&c)
202-
*s++=c;
203-
*s='\0';
200+
c=pqGetString(s,maxlen,Pfin);
204201

205202
#ifdefMULTIBYTE
206-
p=pg_client_to_server(ps,len);
207-
if (ps!=p)
208-
{/* actual conversion has been done? */
209-
strcpy(ps,p);
210-
}
203+
p= (char*)pg_client_to_server((unsignedchar*)s,maxlen);
204+
if (s!=p)/* actual conversion has been done? */
205+
strcpy(s,p);
211206
#endif
212207

213-
/* -----------------
214-
* If EOF reached let caller know.
215-
* (This will only happen if we hit EOF before the string
216-
* delimiter is reached.)
217-
* -----------------
218-
*/
219-
if (c==EOF)
220-
returnEOF;
221-
return !EOF;
208+
returnc;
222209
}
223210

224211
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp