mirror of
https://github.com/postgres/postgres.git
synced 2025-11-24 00:23:06 +03:00
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
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user