Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
a2160c5e
Commit
a2160c5e
authored
20 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Add tests to enlargeStringInfo() to avoid possible buffer-overrun or
infinite-loop problems if a bogus data length is passed.
parent
5ddbe904
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/backend/lib/stringinfo.c
+23
-1
23 additions, 1 deletion
src/backend/lib/stringinfo.c
with
23 additions
and
1 deletion
src/backend/lib/stringinfo.c
+
23
−
1
View file @
a2160c5e
...
@@ -9,13 +9,14 @@
...
@@ -9,13 +9,14 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $PostgreSQL: pgsql/src/backend/lib/stringinfo.c,v 1.3
7
200
3/11/29 22:39:42 pgsq
l Exp $
* $PostgreSQL: pgsql/src/backend/lib/stringinfo.c,v 1.3
8
200
4/05/11 20:07:26 tg
l Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
#include
"postgres.h"
#include
"postgres.h"
#include
"lib/stringinfo.h"
#include
"lib/stringinfo.h"
#include
"utils/memutils.h"
/*
/*
...
@@ -220,7 +221,20 @@ enlargeStringInfo(StringInfo str, int needed)
...
@@ -220,7 +221,20 @@ enlargeStringInfo(StringInfo str, int needed)
{
{
int
newlen
;
int
newlen
;
/*
* Guard against ridiculous "needed" values, which can occur if we're
* fed bogus data. Without this, we can get an overflow or infinite
* loop in the following.
*/
if
(
needed
<
0
||
((
Size
)
needed
)
>=
(
MaxAllocSize
-
(
Size
)
str
->
len
))
elog
(
ERROR
,
"invalid string enlargement request size %d"
,
needed
);
needed
+=
str
->
len
+
1
;
/* total space required now */
needed
+=
str
->
len
+
1
;
/* total space required now */
/* Because of the above test, we now have needed <= MaxAllocSize */
if
(
needed
<=
str
->
maxlen
)
if
(
needed
<=
str
->
maxlen
)
return
;
/* got enough space already */
return
;
/* got enough space already */
...
@@ -234,6 +248,14 @@ enlargeStringInfo(StringInfo str, int needed)
...
@@ -234,6 +248,14 @@ enlargeStringInfo(StringInfo str, int needed)
while
(
needed
>
newlen
)
while
(
needed
>
newlen
)
newlen
=
2
*
newlen
;
newlen
=
2
*
newlen
;
/*
* Clamp to MaxAllocSize in case we went past it. Note we are assuming
* here that MaxAllocSize <= INT_MAX/2, else the above loop could
* overflow. We will still have newlen >= needed.
*/
if
(
newlen
>
(
int
)
MaxAllocSize
)
newlen
=
(
int
)
MaxAllocSize
;
str
->
data
=
(
char
*
)
repalloc
(
str
->
data
,
newlen
);
str
->
data
=
(
char
*
)
repalloc
(
str
->
data
,
newlen
);
str
->
maxlen
=
newlen
;
str
->
maxlen
=
newlen
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment