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

Commit11cc7bb

Browse files
committed
Avoid possibly-unsafe use of Windows' FormatMessage() function.
Whenever this function is used with the FORMAT_MESSAGE_FROM_SYSTEM flag,it's good practice to include FORMAT_MESSAGE_IGNORE_INSERTS as well.Otherwise, if the message contains any %n insertion markers, the functionwill try to fetch argument strings to substitute --- which we are notpassing, possibly leading to a crash. This is exactly analogous to therule about not giving printf() a format string you're not in control of.Noted and patched by Christian Ullrich.Back-patch to all supported branches.
1 parenta3c6439 commit11cc7bb

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

‎src/backend/libpq/auth.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,9 @@ pg_SSPI_error(int severity, const char *errmsg, SECURITY_STATUS r)
12251225
{
12261226
charsysmsg[256];
12271227

1228-
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,r,0,
1228+
if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |
1229+
FORMAT_MESSAGE_FROM_SYSTEM,
1230+
NULL,r,0,
12291231
sysmsg,sizeof(sysmsg),NULL)==0)
12301232
ereport(severity,
12311233
(errmsg_internal("%s",errmsg),

‎src/backend/port/win32/socket.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,9 @@ pgwin32_socket_strerror(int err)
657657
}
658658

659659
ZeroMemory(&wserrbuf,sizeof(wserrbuf));
660-
if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_FROM_HMODULE,
660+
if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |
661+
FORMAT_MESSAGE_FROM_SYSTEM |
662+
FORMAT_MESSAGE_FROM_HMODULE,
661663
handleDLL,
662664
err,
663665
MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT),

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,9 @@ pg_SSPI_error(PGconn *conn, const char *mprefix, SECURITY_STATUS r)
480480
{
481481
charsysmsg[256];
482482

483-
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,r,0,
483+
if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |
484+
FORMAT_MESSAGE_FROM_SYSTEM,
485+
NULL,r,0,
484486
sysmsg,sizeof(sysmsg),NULL)==0)
485487
printfPQExpBuffer(&conn->errorMessage,"%s: SSPI error %x",
486488
mprefix, (unsignedint)r);

‎src/port/dirmod.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ pgsymlink(const char *oldpath, const char *newpath)
207207
LPSTRmsg;
208208

209209
errno=0;
210-
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM,
210+
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
211+
FORMAT_MESSAGE_IGNORE_INSERTS |
212+
FORMAT_MESSAGE_FROM_SYSTEM,
211213
NULL,GetLastError(),
212214
MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT),
213215
(LPSTR)&msg,0,NULL);
@@ -282,7 +284,9 @@ pgreadlink(const char *path, char *buf, size_t size)
282284
LPSTRmsg;
283285

284286
errno=0;
285-
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM,
287+
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
288+
FORMAT_MESSAGE_IGNORE_INSERTS |
289+
FORMAT_MESSAGE_FROM_SYSTEM,
286290
NULL,GetLastError(),
287291
MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT),
288292
(LPSTR)&msg,0,NULL);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp