Skip to content

Commit 3312b8e

Browse files
committed
Load netmsg.dll locally in winsock_strerror, to avoid actual and
potential problems discussed in pgsql-interfaces.
1 parent 9d596e0 commit 3312b8e

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

src/interfaces/libpq/fe-misc.c

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
*
2727
* IDENTIFICATION
28-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.63 2001/11/27 18:21:51 tgl Exp $
28+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.64 2001/11/28 19:40:29 tgl Exp $
2929
*
3030
*-------------------------------------------------------------------------
3131
*/
@@ -37,6 +37,8 @@
3737
#include <time.h>
3838

3939
#ifdef WIN32
40+
#define WIN32_LEAN_AND_MEAN
41+
#include <windows.h>
4042
#include "win32.h"
4143
#else
4244
#include <unistd.h>
@@ -858,41 +860,59 @@ libpq_gettext(const char *msgid)
858860
* If you can verify this working on win9x or have a solution, let us know, ok?
859861
*/
860862
const char *
861-
winsock_strerror(DWORD eno)
863+
winsock_strerror(int eno)
862864
{
863-
#define WSSE_MAXLEN (sizeof(winsock_strerror_buf)-1-12) /* 12 == "(0x00000000)" */
865+
static char err_buf[512];
866+
#define WSSE_MAXLEN (sizeof(err_buf)-1-13) /* 13 == " (0x00000000)" */
867+
HINSTANCE netmsgModule;
864868
int length;
865869

866870
/* First try the "system table", this works on Win2k pro */
867871

868872
if (FormatMessage(
869-
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
870-
0, eno, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
871-
winsock_strerror_buf, WSSE_MAXLEN, NULL
872-
))
873+
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
874+
0,
875+
eno,
876+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
877+
err_buf,
878+
WSSE_MAXLEN,
879+
NULL))
873880
goto WSSE_GOODEXIT;
874881

875882
/* That didn't work, let's try the netmsg.dll */
876883

877-
if (netmsgModule &&
878-
FormatMessage(
879-
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_HMODULE,
880-
0, eno, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
881-
winsock_strerror_buf, WSSE_MAXLEN, NULL
882-
))
883-
goto WSSE_GOODEXIT;
884+
netmsgModule = LoadLibraryEx("netmsg.dll",
885+
NULL,
886+
LOAD_LIBRARY_AS_DATAFILE);
887+
888+
if (netmsgModule != NULL)
889+
{
890+
if (FormatMessage(
891+
FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_HMODULE,
892+
netmsgModule,
893+
eno,
894+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
895+
err_buf,
896+
WSSE_MAXLEN,
897+
NULL))
898+
{
899+
FreeLibrary(netmsgModule);
900+
goto WSSE_GOODEXIT;
901+
}
902+
FreeLibrary(netmsgModule);
903+
}
884904

885905
/* Everything failed, just tell the user that we don't know the desc */
886906

887-
strcpy(winsock_strerror_buf, "Socket error, no description available.");
907+
strcpy(err_buf, "Socket error, no description available.");
888908

889909
WSSE_GOODEXIT:
890910

891-
length = strlen(winsock_strerror_buf);
892-
sprintf(winsock_strerror_buf + (length < WSSE_MAXLEN ? length : WSSE_MAXLEN),
893-
"(0x%08X)", eno);
911+
length = strlen(err_buf);
912+
sprintf(err_buf + (length < WSSE_MAXLEN ? length : WSSE_MAXLEN),
913+
" (0x%08X)", eno);
894914

895-
return winsock_strerror_buf;
915+
return err_buf;
896916
}
897917

898918
#endif

src/interfaces/libpq/libpqdll.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#define WIN32_LEAN_AND_MEAN
22
#include <windows.h>
3-
#include <winsock.h>
43
#include "win32.h"
54

5+
66
BOOL WINAPI
77
DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
88
LPVOID lpReserved)
@@ -20,12 +20,8 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
2020
*/
2121
return FALSE;
2222
}
23-
if (netmsgModule == NULL)
24-
netmsgModule = LoadLibraryEx("netmsg.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
2523
break;
2624
case DLL_PROCESS_DETACH:
27-
if (netmsgModule != NULL)
28-
FreeLibrary(netmsgModule);
2925
WSACleanup();
3026
break;
3127
}

src/interfaces/libpq/win32.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
#define EINPROGRESS WSAEINPROGRESS
3232

3333
/*
34-
* Windows network messaging stuff:
34+
* support for handling Windows Socket errors
3535
*/
36-
static HINSTANCE netmsgModule = NULL;
37-
38-
static char winsock_strerror_buf[512];
39-
const char *winsock_strerror(DWORD eno);
36+
extern const char *winsock_strerror(int eno);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy