~ubuntu-branches/ubuntu/utopic/postgresql-9.4/utopic-security

« back to all changes in this revision

Viewing changes to src/include/utils/datetime.h

  • Committer: Package Import Robot
  • Author(s): Martin Pitt, CVE-2014-8161
  • Date: 2015-02-06 12:31:46 UTC
  • mfrom: (1.1.5) (7.1.2 utopic-proposed)
  • Revision ID: package-import@ubuntu.com-20150206123146-vtmf30jbkm7w16p8
Tags: 9.4.1-0ubuntu0.14.10
* New upstream security/bug fix release (LP: #1418928)
  - Fix buffer overruns in to_char() [CVE-2015-0241]
  - Fix buffer overruns in contrib/pgcrypto [CVE-2015-0243]
  - Fix possible loss of frontend/backend protocol synchronization after an
    error [CVE-2015-0244]
  - Fix information leak via constraint-violation error messages
    [CVE-2014-8161]
  - See release notes for details about other fixes:
    http://www.postgresql.org/about/news/1569/

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
#define BC              1
78
78
 
79
79
/*
80
 
 * Fields for time decoding.
 
80
 * Field types for time decoding.
81
81
 *
82
82
 * Can't have more of these than there are bits in an unsigned int
83
83
 * since these are turned into bit masks during parsing and decoding.
93
93
#define YEAR    2
94
94
#define DAY             3
95
95
#define JULIAN  4
96
 
#define TZ              5
97
 
#define DTZ             6
98
 
#define DTZMOD  7
 
96
#define TZ              5                               /* fixed-offset timezone abbreviation */
 
97
#define DTZ             6                               /* fixed-offset timezone abbrev, DST */
 
98
#define DYNTZ   7                               /* dynamic timezone abbreviation */
99
99
#define IGNORE_DTF      8
100
100
#define AMPM    9
101
101
#define HOUR    10
119
119
#define DECADE          25
120
120
#define CENTURY         26
121
121
#define MILLENNIUM      27
 
122
/* hack for parsing two-word timezone specs "MET DST" etc */
 
123
#define DTZMOD  28                              /* "DST" as a separate word */
122
124
/* reserved for unrecognized string values */
123
125
#define UNKNOWN_FIELD   31
124
126
 
125
127
/*
126
128
 * Token field definitions for time parsing and decoding.
127
 
 * These need to fit into the datetkn table type.
128
 
 * At the moment, that means keep them within [-127,127].
129
 
 * These are also used for bit masks in DecodeDateDelta()
 
129
 *
 
130
 * Some field type codes (see above) use these as the "value" in datetktbl[].
 
131
 * These are also used for bit masks in DecodeDateTime and friends
130
132
 *      so actually restrict them to within [0,31] for now.
131
133
 * - thomas 97/06/19
132
 
 * Not all of these fields are used for masks in DecodeDateDelta
 
134
 * Not all of these fields are used for masks in DecodeDateTime
133
135
 *      so allow some larger than 31. - thomas 1997-11-17
 
136
 *
 
137
 * Caution: there are undocumented assumptions in the code that most of these
 
138
 * values are not equal to IGNORE_DTF nor RESERV.  Be very careful when
 
139
 * renumbering values in either of these apparently-independent lists :-(
134
140
 */
135
141
 
136
142
#define DTK_NUMBER              0
203
209
/* keep this struct small; it gets used a lot */
204
210
typedef struct
205
211
{
206
 
        char            token[TOKMAXLEN];
207
 
        char            type;
208
 
        char            value;                  /* this may be unsigned, alas */
 
212
        char            token[TOKMAXLEN + 1];   /* always NUL-terminated */
 
213
        char            type;                   /* see field type codes above */
 
214
        int32           value;                  /* meaning depends on type */
209
215
} datetkn;
210
216
 
211
217
/* one of its uses is in tables of time zone abbreviations */
212
218
typedef struct TimeZoneAbbrevTable
213
219
{
214
 
        int                     numabbrevs;
 
220
        Size            tblsize;                /* size in bytes of TimeZoneAbbrevTable */
 
221
        int                     numabbrevs;             /* number of entries in abbrevs[] array */
215
222
        datetkn         abbrevs[1];             /* VARIABLE LENGTH ARRAY */
 
223
        /* DynamicZoneAbbrev(s) may follow the abbrevs[] array */
216
224
} TimeZoneAbbrevTable;
217
225
 
 
226
/* auxiliary data for a dynamic time zone abbreviation (non-fixed-offset) */
 
227
typedef struct DynamicZoneAbbrev
 
228
{
 
229
        pg_tz      *tz;                         /* NULL if not yet looked up */
 
230
        char            zone[1];                /* zone name (var length, NUL-terminated) */
 
231
} DynamicZoneAbbrev;
 
232
 
218
233
 
219
234
/* FMODULO()
220
235
 * Macro to replace modf(), which is broken on some platforms.
296
311
                                   const char *datatype) __attribute__((noreturn));
297
312
 
298
313
extern int      DetermineTimeZoneOffset(struct pg_tm * tm, pg_tz *tzp);
 
314
extern int      DetermineTimeZoneAbbrevOffset(struct pg_tm * tm, const char *abbr, pg_tz *tzp);
 
315
extern int DetermineTimeZoneAbbrevOffsetTS(TimestampTz ts, const char *abbr,
 
316
                                                                pg_tz *tzp, int *isdst);
299
317
 
300
318
extern void EncodeDateOnly(struct pg_tm * tm, int style, char *str);
301
319
extern void EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, bool print_tz, int tz, int style, char *str);
305
323
extern int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc,
306
324
                         struct pg_tm * tm);
307
325
 
 
326
extern int DecodeTimezoneAbbrev(int field, char *lowtoken,
 
327
                                         int *offset, pg_tz **tz);
308
328
extern int      DecodeSpecial(int field, char *lowtoken, int *val);
309
329
extern int      DecodeUnits(int field, char *lowtoken, int *val);
310
330
 
314
334
 
315
335
extern bool CheckDateTokenTables(void);
316
336
 
317
 
extern void ConvertTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl,
318
 
                                           struct tzEntry *abbrevs, int n);
 
337
extern TimeZoneAbbrevTable *ConvertTimeZoneAbbrevs(struct tzEntry *abbrevs,
 
338
                                           int n);
319
339
extern void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl);
320
340
 
321
341
extern Datum pg_timezone_abbrevs(PG_FUNCTION_ARGS);