diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-12-16 15:35:36 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-12-16 15:35:36 -0500 |
commit | 383d224a02a4c481b20c20a0d36e390011d835b7 (patch) | |
tree | 69f070d52007e3ff2fad3f294807286d82181a51 /src/include/bootstrap/bootstrap.h | |
parent | f2a3cdb6dbe4984c7b5461ed4ece789eab2faf4a (diff) |
Fix off-by-one loop count in MapArrayTypeName, and get rid of static array.
MapArrayTypeName would copy up to NAMEDATALEN-1 bytes of the base type
name, which of course is wrong: after prepending '_' there is only room for
NAMEDATALEN-2 bytes. Aside from being the wrong result, this case would
lead to overrunning the statically allocated work buffer. This would be a
security bug if the function were ever used outside bootstrap mode, but it
isn't, at least not in any currently supported branches.
Aside from fixing the off-by-one loop logic, this patch gets rid of the
static work buffer by having MapArrayTypeName pstrdup its result; the sole
caller was already doing that, so this just requires moving the pstrdup
call. This saves a few bytes but mainly it makes the API a lot cleaner.
Back-patch on the off chance that there is some third-party code using
MapArrayTypeName with less-secure input. Pushing pstrdup into the function
should not cause any serious problems for such hypothetical code; at worst
there might be a short term memory leak.
Per Coverity scanning.
Diffstat (limited to 'src/include/bootstrap/bootstrap.h')
-rw-r--r-- | src/include/bootstrap/bootstrap.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/include/bootstrap/bootstrap.h b/src/include/bootstrap/bootstrap.h index 24ad93dbe97..6d8393eecf1 100644 --- a/src/include/bootstrap/bootstrap.h +++ b/src/include/bootstrap/bootstrap.h @@ -40,7 +40,7 @@ extern void InsertOneTuple(Oid objectid); extern void InsertOneValue(char *value, int i); extern void InsertOneNull(int i); -extern char *MapArrayTypeName(char *s); +extern char *MapArrayTypeName(const char *s); extern void index_register(Oid heap, Oid ind, IndexInfo *indexInfo); extern void build_indices(void); |