Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
70d4a934
Commit
70d4a934
authored
Mar 02, 2005
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent large allocation in snprintf to hold positional parameters.
Allocated size based on format string.
parent
3104a928
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
15 deletions
+38
-15
src/port/snprintf.c
src/port/snprintf.c
+38
-15
No files found.
src/port/snprintf.c
View file @
70d4a934
...
...
@@ -32,18 +32,17 @@
* SUCH DAMAGE.
*/
/* might be in either frontend or backend */
#ifndef FRONTEND
#include "postgres.h"
#else
#include "postgres_fe.h"
#endif
#ifndef WIN32
#include <sys/ioctl.h>
#endif
#include <sys/param.h>
#ifndef NL_ARGMAX
#define NL_ARGMAX 4096
#endif
/*
** SNPRINTF, VSNPRINT -- counted versions of printf
**
...
...
@@ -66,7 +65,7 @@
* causing nasty effects.
**************************************************************/
/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.1
1 2005/03/02 03:21:5
2 momjian Exp $";*/
/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.1
2 2005/03/02 05:22:2
2 momjian Exp $";*/
int
snprintf
(
char
*
str
,
size_t
count
,
const
char
*
fmt
,...);
int
vsnprintf
(
char
*
str
,
size_t
count
,
const
char
*
fmt
,
va_list
args
);
...
...
@@ -157,11 +156,9 @@ dopr(char *buffer, const char *format, va_list args, char *end)
int
realpos
=
0
;
int
position
;
char
*
output
;
/* In thread mode this structure is too large. */
#ifndef ENABLE_THREAD_SAFETY
static
#endif
struct
{
int
percents
=
1
;
const
char
*
p
;
struct
fmtpar
{
const
char
*
fmtbegin
;
const
char
*
fmtend
;
void
*
value
;
...
...
@@ -179,10 +176,30 @@ dopr(char *buffer, const char *format, va_list args, char *end)
int
pointflag
;
char
func
;
int
realpos
;
}
fmtpar
[
NL_ARGMAX
+
1
],
*
fmtparptr
[
NL_ARGMAX
+
1
]
;
}
*
fmtpar
,
**
fmtparptr
;
/* Create enough structures to hold all arguments */
for
(
p
=
format
;
*
p
!=
'\0'
;
p
++
)
if
(
*
p
==
'%'
)
/* counts %% as two, so overcounts */
percents
++
;
#ifndef FRONTEND
fmtpar
=
pgport_palloc
(
sizeof
(
struct
fmtpar
)
*
percents
);
fmtparptr
=
pgport_palloc
(
sizeof
(
struct
fmtpar
*
)
*
percents
);
#else
if
((
fmtpar
=
malloc
(
sizeof
(
struct
fmtpar
)
*
percents
))
==
NULL
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
1
);
}
if
((
fmtparptr
=
malloc
(
sizeof
(
struct
fmtpar
*
)
*
percents
))
==
NULL
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
1
);
}
#endif
format_save
=
format
;
output
=
buffer
;
while
((
ch
=
*
format
++
))
{
...
...
@@ -418,9 +435,7 @@ dopr(char *buffer, const char *format, va_list args, char *end)
performpr:
/* shuffle pointers */
for
(
i
=
1
;
i
<
fmtpos
;
i
++
)
{
fmtparptr
[
i
]
=
&
fmtpar
[
fmtpar
[
i
].
realpos
];
}
output
=
buffer
;
format
=
format_save
;
while
((
ch
=
*
format
++
))
...
...
@@ -465,6 +480,14 @@ nochar:
;
/* semicolon required because a goto has to be attached to a statement */
}
*
output
=
'\0'
;
#ifndef FRONTEND
pgport_pfree
(
fmtpar
);
pgport_pfree
(
fmtparptr
);
#else
free
(
fmtpar
);
free
(
fmtparptr
);
#endif
}
static
void
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment