Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b01f32c

Browse files
committed
Fix some dubious WAL-parsing code.
Coverity complained about possible buffer overrun in two places added by commit 1eb6d65, and AFAICS it's reasonable to worry: even granting that the WAL originator properly truncated the commit GID to GIDSIZE, we should not really bet our lives on that having the same value as it does in the current build. Hence, use strlcpy() not strcpy(), and adjust the pointer advancement logic to be sure we skip over the whole source string even if strlcpy() truncated it.
1 parent 05e85d3 commit b01f32c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/backend/access/rmgrdesc/xactdesc.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *pars
106106
if (parsed->xinfo & XACT_XINFO_HAS_GID)
107107
{
108108
int gidlen;
109-
strcpy(parsed->twophase_gid, data);
110-
gidlen = strlen(parsed->twophase_gid) + 1;
109+
strlcpy(parsed->twophase_gid, data, sizeof(parsed->twophase_gid));
110+
gidlen = strlen(data) + 1;
111111
data += MAXALIGN(gidlen);
112112
}
113113
}
@@ -190,8 +190,8 @@ ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
190190
if (parsed->xinfo & XACT_XINFO_HAS_GID)
191191
{
192192
int gidlen;
193-
strcpy(parsed->twophase_gid, data);
194-
gidlen = strlen(parsed->twophase_gid) + 1;
193+
strlcpy(parsed->twophase_gid, data, sizeof(parsed->twophase_gid));
194+
gidlen = strlen(data) + 1;
195195
data += MAXALIGN(gidlen);
196196
}
197197
}

0 commit comments

Comments
 (0)