aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/network.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-12-14 13:22:08 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2022-12-14 13:22:08 -0500
commit17407a8eaa2afa8ac0de4b0a494f33d8eb7a98bd (patch)
tree2fa2bc7dcfb3221e36390123978817174239fb71 /src/backend/utils/adt/network.c
parentb18c2decd76eeffbd483c041c02bb0fb01b0f124 (diff)
downloadpostgresql-17407a8eaa2afa8ac0de4b0a494f33d8eb7a98bd.tar.gz
postgresql-17407a8eaa2afa8ac0de4b0a494f33d8eb7a98bd.zip
Convert a few more datatype input functions to report errors softly.
Convert bit_in, varbit_in, inet_in, cidr_in, macaddr_in, and macaddr8_in to the new style. Amul Sul, minor mods by me Discussion: https://postgr.es/m/CAAJ_b97KeDWUdpTKGOaFYPv0OicjOu6EW+QYWj-Ywrgj_aEy1g@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/network.c')
-rw-r--r--src/backend/utils/adt/network.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index 6d580ea78f6..42a4d9d44ec 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -72,7 +72,7 @@ static inet *internal_inetpl(inet *ip, int64 addend);
* Common INET/CIDR input routine
*/
static inet *
-network_in(char *src, bool is_cidr)
+network_in(char *src, bool is_cidr, Node *escontext)
{
int bits;
inet *dst;
@@ -93,7 +93,7 @@ network_in(char *src, bool is_cidr)
bits = pg_inet_net_pton(ip_family(dst), src, ip_addr(dst),
is_cidr ? ip_addrsize(dst) : -1);
if ((bits < 0) || (bits > ip_maxbits(dst)))
- ereport(ERROR,
+ ereturn(escontext, NULL,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
/* translator: first %s is inet or cidr */
errmsg("invalid input syntax for type %s: \"%s\"",
@@ -105,7 +105,7 @@ network_in(char *src, bool is_cidr)
if (is_cidr)
{
if (!addressOK(ip_addr(dst), bits, ip_family(dst)))
- ereport(ERROR,
+ ereturn(escontext, NULL,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid cidr value: \"%s\"", src),
errdetail("Value has bits set to right of mask.")));
@@ -122,7 +122,7 @@ inet_in(PG_FUNCTION_ARGS)
{
char *src = PG_GETARG_CSTRING(0);
- PG_RETURN_INET_P(network_in(src, false));
+ PG_RETURN_INET_P(network_in(src, false, fcinfo->context));
}
Datum
@@ -130,7 +130,7 @@ cidr_in(PG_FUNCTION_ARGS)
{
char *src = PG_GETARG_CSTRING(0);
- PG_RETURN_INET_P(network_in(src, true));
+ PG_RETURN_INET_P(network_in(src, true, fcinfo->context));
}
@@ -1742,7 +1742,7 @@ inet_client_addr(PG_FUNCTION_ARGS)
clean_ipv6_addr(port->raddr.addr.ss_family, remote_host);
- PG_RETURN_INET_P(network_in(remote_host, false));
+ PG_RETURN_INET_P(network_in(remote_host, false, NULL));
}
@@ -1814,7 +1814,7 @@ inet_server_addr(PG_FUNCTION_ARGS)
clean_ipv6_addr(port->laddr.addr.ss_family, local_host);
- PG_RETURN_INET_P(network_in(local_host, false));
+ PG_RETURN_INET_P(network_in(local_host, false, NULL));
}