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

Commit8ec00dc

Browse files
committed
Remove undesirable libpq dependency on stringinfo.c.
Commitc0cb87f unwisely introduced a dependency on the StringInfomachinery in fe-connect.c. We must not use that in libpq, becauseit will do a summary exit(1) if it hits OOM, and that is notappropriate behavior for a general-purpose library. The goal ofallowing arbitrary line lengths in service files doesn't seem likeit's worth a lot of effort, so revert back to the previous methodof using a stack-allocated buffer and failing on buffer overflow.This isn't an exact revert though. I kept that patch's refactoringto have a single exit path, as that seems cleaner than having eacherror path know what to do to clean up. Also, I made the fixed-sizebuffer 1024 bytes not 256, just to push off the need for an expandablebuffer some more.There is more to do here; in particular the lack of any mechanicalcheck for this type of mistake now seems pretty hazardous. But thisfix gets us back to the level of robustness we had in v13, anyway.Discussion:https://postgr.es/m/daeb22ec6ca8ef61e94d766a9b35fb03cabed38e.camel@vmware.com
1 parentd5a2c41 commit8ec00dc

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include"fe-auth.h"
2929
#include"libpq-fe.h"
3030
#include"libpq-int.h"
31-
#include"lib/stringinfo.h"
3231
#include"mb/pg_wchar.h"
3332
#include"pg_config_paths.h"
3433
#include"port/pg_bswap.h"
@@ -5163,7 +5162,7 @@ parseServiceFile(const char *serviceFile,
51635162
i;
51645163
FILE*f;
51655164
char*line;
5166-
StringInfoDatalinebuf;
5165+
charbuf[1024];
51675166

51685167
*group_found= false;
51695168

@@ -5175,18 +5174,26 @@ parseServiceFile(const char *serviceFile,
51755174
return1;
51765175
}
51775176

5178-
initStringInfo(&linebuf);
5179-
5180-
while (pg_get_line_buf(f,&linebuf))
5177+
while ((line=fgets(buf,sizeof(buf),f))!=NULL)
51815178
{
5179+
intlen;
5180+
51825181
linenr++;
51835182

5184-
/* ignore whitespace at end of line, especially the newline */
5185-
while (linebuf.len>0&&
5186-
isspace((unsignedchar)linebuf.data[linebuf.len-1]))
5187-
linebuf.data[--linebuf.len]='\0';
5183+
if (strlen(line) >=sizeof(buf)-1)
5184+
{
5185+
appendPQExpBuffer(errorMessage,
5186+
libpq_gettext("line %d too long in service file \"%s\"\n"),
5187+
linenr,
5188+
serviceFile);
5189+
result=2;
5190+
gotoexit;
5191+
}
51885192

5189-
line=linebuf.data;
5193+
/* ignore whitespace at end of line, especially the newline */
5194+
len=strlen(line);
5195+
while (len>0&&isspace((unsignedchar)line[len-1]))
5196+
line[--len]='\0';
51905197

51915198
/* ignore leading whitespace too */
51925199
while (*line&&isspace((unsignedchar)line[0]))
@@ -5303,7 +5310,6 @@ parseServiceFile(const char *serviceFile,
53035310

53045311
exit:
53055312
fclose(f);
5306-
pfree(linebuf.data);
53075313

53085314
returnresult;
53095315
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp