Skip to content

Commit 3bc6bdf

Browse files
committed
Define snprintf() to call pg_snprintf() so our own snprintf-like
implementation doesn't export out via libpq and get used by a user application.
1 parent 6521cd9 commit 3bc6bdf

File tree

7 files changed

+52
-23
lines changed

7 files changed

+52
-23
lines changed

configure

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14973,6 +14973,11 @@ _ACEOF
1497314973

1497414974
# Now we have checked all the reasons to replace snprintf
1497514975
if test $pgac_need_repl_snprintf = yes; then
14976+
14977+
cat >>confdefs.h <<\_ACEOF
14978+
#define USE_SNPRINTF 1
14979+
_ACEOF
14980+
1497614981
LIBOBJS="$LIBOBJS snprintf.$ac_objext"
1497714982
fi
1497814983

configure.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.405 2005/03/02 15:42:35 momjian Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.406 2005/03/11 17:20:33 momjian Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -1143,6 +1143,7 @@ AC_DEFINE_UNQUOTED(UINT64_FORMAT, $UINT64_FORMAT,
11431143

11441144
# Now we have checked all the reasons to replace snprintf
11451145
if test $pgac_need_repl_snprintf = yes; then
1146+
AC_DEFINE(USE_SNPRINTF, 1, [Use replacement snprintf() functions.])
11461147
AC_LIBOBJ(snprintf)
11471148
fi
11481149

src/bin/pg_ctl/pg_ctl.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.54 2005/02/22 04:39:22 momjian Exp $
7+
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.55 2005/03/11 17:20:33 momjian Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -337,19 +337,23 @@ start_postmaster(void)
337337
if (log_file != NULL)
338338
#ifndef WIN32 /* Cygwin doesn't have START */
339339
snprintf(cmd, MAXPGPATH, "%s\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1 &%s",
340+
SYSTEMQUOTE, postgres_path, pgdata_opt, post_opts,
341+
DEVNULL, log_file, SYSTEMQUOTE);
340342
#else
341343
snprintf(cmd, MAXPGPATH, "%sSTART /B \"\" \"%s\" %s%s < \"%s\" >> \"%s\" 2>&1%s",
342-
#endif
343344
SYSTEMQUOTE, postgres_path, pgdata_opt, post_opts,
344345
DEVNULL, log_file, SYSTEMQUOTE);
346+
#endif
345347
else
346348
#ifndef WIN32 /* Cygwin doesn't have START */
347349
snprintf(cmd, MAXPGPATH, "%s\"%s\" %s%s < \"%s\" 2>&1 &%s",
350+
SYSTEMQUOTE, postgres_path, pgdata_opt, post_opts,
351+
DEVNULL, SYSTEMQUOTE);
348352
#else
349353
snprintf(cmd, MAXPGPATH, "%sSTART /B \"\" \"%s\" %s%s < \"%s\" 2>&1%s",
350-
#endif
351354
SYSTEMQUOTE, postgres_path, pgdata_opt, post_opts,
352355
DEVNULL, SYSTEMQUOTE);
356+
#endif
353357

354358
return system(cmd);
355359
}

src/bin/psql/command.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.140 2005/02/22 04:40:51 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.141 2005/03/11 17:20:34 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -1175,13 +1175,13 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
11751175
* supplied path unless we use only backslashes, so we do that.
11761176
*/
11771177
#endif
1178-
snprintf(fnametmp, sizeof(fnametmp), "%s%spsql.edit.%d", tmpdir,
11791178
#ifndef WIN32
1180-
"/",
1179+
snprintf(fnametmp, sizeof(fnametmp), "%s%spsql.edit.%d", tmpdir,
1180+
"/", (int)getpid());
11811181
#else
1182-
"", /* trailing separator already present */
1182+
snprintf(fnametmp, sizeof(fnametmp), "%s%spsql.edit.%d", tmpdir,
1183+
"" /* trailing separator already present */, (int)getpid());
11831184
#endif
1184-
(int)getpid());
11851185

11861186
fname = (const char *) fnametmp;
11871187

src/include/pg_config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,9 @@
648648
/* Define to 1 to build with Rendezvous support. (--with-rendezvous) */
649649
#undef USE_RENDEZVOUS
650650

651+
/* Use replacement snprintf() functions. */
652+
#undef USE_SNPRINTF
653+
651654
/* Define to build with (Open)SSL support. (--with-openssl) */
652655
#undef USE_SSL
653656

src/include/port.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/port.h,v 1.70 2005/02/27 00:53:29 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/port.h,v 1.71 2005/03/11 17:20:34 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -107,6 +107,26 @@ extern int pg_strncasecmp(const char *s1, const char *s2, size_t n);
107107
extern unsigned char pg_toupper(unsigned char ch);
108108
extern unsigned char pg_tolower(unsigned char ch);
109109

110+
#ifdef USE_SNPRINTF
111+
extern int pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
112+
extern int pg_snprintf(char *str, size_t count, const char *fmt,...)
113+
/* This extension allows gcc to check the format string */
114+
__attribute__((format(printf, 3, 4)));
115+
extern int pg_printf(const char *fmt,...)
116+
/* This extension allows gcc to check the format string */
117+
__attribute__((format(printf, 1, 2)));
118+
119+
#ifdef __GNUC__
120+
#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
121+
#define snprintf(...) pg_snprintf(__VA_ARGS__)
122+
#define printf(...) pg_printf(__VA_ARGS__)
123+
#else
124+
#define vsnprintf pg_vsnprintf
125+
#define snprintf pg_snprintf
126+
#define printf pg_printf
127+
#endif
128+
#endif
129+
110130
/* Portable prompt handling */
111131
extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
112132

src/port/snprintf.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,15 @@
6565
* causing nasty effects.
6666
**************************************************************/
6767

68-
/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.16 2005/03/02 23:56:53 momjian Exp $";*/
68+
/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.17 2005/03/11 17:20:35 momjian Exp $";*/
6969

70-
int snprintf(char *str, size_t count, const char *fmt,...);
71-
int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
72-
int printf(const char *format, ...);
70+
int pg_snprintf(char *str, size_t count, const char *fmt,...);
71+
int pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
72+
int pg_printf(const char *format, ...);
7373
static void dopr(char *buffer, const char *format, va_list args, char *end);
7474

75-
/*
76-
* If vsnprintf() is not before snprintf() in this file, snprintf()
77-
* will call the system vsnprintf() on MinGW.
78-
*/
7975
int
80-
vsnprintf(char *str, size_t count, const char *fmt, va_list args)
76+
pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
8177
{
8278
char *end;
8379
str[0] = '\0';
@@ -89,27 +85,27 @@ vsnprintf(char *str, size_t count, const char *fmt, va_list args)
8985
}
9086

9187
int
92-
snprintf(char *str, size_t count, const char *fmt,...)
88+
pg_snprintf(char *str, size_t count, const char *fmt,...)
9389
{
9490
int len;
9591
va_list args;
9692

9793
va_start(args, fmt);
98-
len = vsnprintf(str, count, fmt, args);
94+
len = pg_vsnprintf(str, count, fmt, args);
9995
va_end(args);
10096
return len;
10197
}
10298

10399
int
104-
printf(const char *fmt,...)
100+
pg_printf(const char *fmt,...)
105101
{
106102
int len;
107103
va_list args;
108104
char* buffer[4096];
109105
char* p;
110106

111107
va_start(args, fmt);
112-
len = vsnprintf((char*)buffer, (size_t)4096, fmt, args);
108+
len = pg_vsnprintf((char*)buffer, (size_t)4096, fmt, args);
113109
va_end(args);
114110
p = (char*)buffer;
115111
for(;*p;p++)

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