summaryrefslogtreecommitdiff
path: root/src/include/utils/datetime.h
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2014-02-17 09:33:31 -0500
committerNoah Misch <noah@leadboat.com>2014-02-17 09:33:32 -0500
commite4a4fa22352b062bc3548c91fa9bfc6caed7b073 (patch)
tree65e1c82e94c7f3fc74618e07a2a96e427f6adad2 /src/include/utils/datetime.h
parente1e0a4d791292ebe9572451a6cf49fb0ccb320c7 (diff)
Fix handling of wide datetime input/output.
Many server functions use the MAXDATELEN constant to size a buffer for parsing or displaying a datetime value. It was much too small for the longest possible interval output and slightly too small for certain valid timestamp input, particularly input with a long timezone name. The long input was rejected needlessly; the long output caused interval_out() to overrun its buffer. ECPG's pgtypes library has a copy of the vulnerable functions, which bore the same vulnerabilities along with some of its own. In contrast to the server, certain long inputs caused stack overflow rather than failing cleanly. Back-patch to 8.4 (all supported versions). Reported by Daniel Schüssler, reviewed by Tom Lane. Security: CVE-2014-0063
Diffstat (limited to 'src/include/utils/datetime.h')
-rw-r--r--src/include/utils/datetime.h17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/include/utils/datetime.h b/src/include/utils/datetime.h
index 3cd921a0dbb..02e63b3bfc6 100644
--- a/src/include/utils/datetime.h
+++ b/src/include/utils/datetime.h
@@ -188,12 +188,17 @@ struct tzEntry;
#define DTK_DATE_M (DTK_M(YEAR) | DTK_M(MONTH) | DTK_M(DAY))
#define DTK_TIME_M (DTK_M(HOUR) | DTK_M(MINUTE) | DTK_ALL_SECS_M)
-#define MAXDATELEN 63 /* maximum possible length of an input date
- * string (not counting tr. null) */
-#define MAXDATEFIELDS 25 /* maximum possible number of fields in a date
- * string */
-#define TOKMAXLEN 10 /* only this many chars are stored in
- * datetktbl */
+/*
+ * Working buffer size for input and output of interval, timestamp, etc.
+ * Inputs that need more working space will be rejected early. Longer outputs
+ * will overrun buffers, so this must suffice for all possible output. As of
+ * this writing, interval_out() needs the most space at ~90 bytes.
+ */
+#define MAXDATELEN 128
+/* maximum possible number of fields in a date string */
+#define MAXDATEFIELDS 25
+/* only this many chars are stored in datetktbl */
+#define TOKMAXLEN 10
/* keep this struct small; it gets used a lot */
typedef struct