aboutsummaryrefslogtreecommitdiff
path: root/src/include/utils/builtins.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-12-27 11:40:01 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2022-12-27 11:40:01 -0500
commiteb8312a22a84c33fc405ae9b497113973f552f90 (patch)
tree3d7a135bafd3fd06750a6586e69225447743caae /src/include/utils/builtins.h
parent63c844a0a5d70cdbd6ae0470d582d39e75ad8d66 (diff)
downloadpostgresql-eb8312a22a84c33fc405ae9b497113973f552f90.tar.gz
postgresql-eb8312a22a84c33fc405ae9b497113973f552f90.zip
Detect bad input for types xid, xid8, and cid.
Historically these input functions just called strtoul or strtoull and returned the result, with no error detection whatever. Upgrade them to reject garbage input and out-of-range values, similarly to our other numeric input routines. To share the code for this with type oid, adjust the existing "oidin_subr" to be agnostic about the SQL name of the type it is handling, and move it to numutils.c; then clone it for 64-bit types. Because the xid types previously accepted hex and octal input by reason of calling strtoul[l] with third argument zero, I made the common subroutine do that too, with the consequence that type oid now also accepts hex and octal input. In view of 6fcda9aba, that seems like a good thing. While at it, simplify the existing over-complicated handling of syntax errors from strtoul: we only need one ereturn not three. Discussion: https://postgr.es/m/3526121.1672000729@sss.pgh.pa.us
Diffstat (limited to 'src/include/utils/builtins.h')
-rw-r--r--src/include/utils/builtins.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index 15373ba68f7..a4a20b5a453 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -51,6 +51,10 @@ extern int32 pg_strtoint32(const char *s);
extern int32 pg_strtoint32_safe(const char *s, Node *escontext);
extern int64 pg_strtoint64(const char *s);
extern int64 pg_strtoint64_safe(const char *s, Node *escontext);
+extern uint32 uint32in_subr(const char *s, char **endloc,
+ const char *typname, Node *escontext);
+extern uint64 uint64in_subr(const char *s, char **endloc,
+ const char *typname, Node *escontext);
extern int pg_itoa(int16 i, char *a);
extern int pg_ultoa_n(uint32 value, char *a);
extern int pg_ulltoa_n(uint64 value, char *a);