1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-25 01:02:05 +03:00
Files
postgres/src/include/bootstrap/bootstrap.h
Tom Lane 66709133c7 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.
2014-12-16 15:35:33 -05:00

63 lines
1.6 KiB
C

/*-------------------------------------------------------------------------
*
* bootstrap.h
* include file for the bootstrapping code
*
*
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/bootstrap/bootstrap.h
*
*-------------------------------------------------------------------------
*/
#ifndef BOOTSTRAP_H
#define BOOTSTRAP_H
#include "nodes/execnodes.h"
/*
* MAXATTR is the maximum number of attributes in a relation supported
* at bootstrap time (i.e., the max possible in a system table).
*/
#define MAXATTR 40
extern Relation boot_reldesc;
extern Form_pg_attribute attrtypes[MAXATTR];
extern int numattr;
extern void AuxiliaryProcessMain(int argc, char *argv[]) __attribute__((noreturn));
extern void err_out(void);
extern void closerel(char *name);
extern void boot_openrel(char *name);
extern void DefineAttr(char *name, char *type, int attnum);
extern void InsertOneTuple(Oid objectid);
extern void InsertOneValue(char *value, int i);
extern void InsertOneNull(int i);
extern char *MapArrayTypeName(const char *s);
extern void index_register(Oid heap, Oid ind, IndexInfo *indexInfo);
extern void build_indices(void);
extern void boot_get_type_io_data(Oid typid,
int16 *typlen,
bool *typbyval,
char *typalign,
char *typdelim,
Oid *typioparam,
Oid *typinput,
Oid *typoutput);
extern int boot_yyparse(void);
extern int boot_yylex(void);
extern void boot_yyerror(const char *str) __attribute__((noreturn));
#endif /* BOOTSTRAP_H */