Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 439C363279C for ; Wed, 18 Feb 2009 03:35:00 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 00133-05 for ; Wed, 18 Feb 2009 03:34:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail63.csoft.net (mail63.csoft.net [205.205.214.4]) by mail.postgresql.org (Postfix) with ESMTP id AD491632793 for ; Wed, 18 Feb 2009 03:34:52 -0400 (AST) Received: from [192.168.7.2] (cpe-76-94-246-223.socal.res.rr.com [76.94.246.223]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail63.csoft.net (Postfix) with ESMTP id 2F98928413; Wed, 18 Feb 2009 02:34:50 -0500 (EST) Message-ID: <499BBA18.2000309@ejurka.com> Date: Tue, 17 Feb 2009 23:34:48 -0800 From: Kris Jurka User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: Thomas Hallgren CC: Tom Lane , pljava-dev@pgfoundry.org, pgsql-hackers@postgresql.org, Alvaro Herrera Subject: Re: [Pljava-dev] Re: Should creating a new base type require superuser status? References: <19715.1217447413@sss.pgh.pa.us> <20080730220753.GG3977@alvh.no-ip.org> <23846.1217539394@sss.pgh.pa.us> <48937589.10304@tada.se> <23725.1217626961@sss.pgh.pa.us> <48940239.8080401@tada.se> <4111.1217693570@sss.pgh.pa.us> <499BA58F.8000706@tada.se> In-Reply-To: <499BA58F.8000706@tada.se> Content-Type: multipart/mixed; boundary="------------010704090706070904030508" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200902/923 X-Sequence-Number: 134213 This is a multi-part message in MIME format. --------------010704090706070904030508 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Thomas Hallgren wrote: > Kris Jurka wrote: >> >> 3) By value: pljava does not correctly handle passed by value types >> correctly, allowing access to random memory. >> > This is simply not true. There's no way a Java developer can access > random memory through PL/Java. No, the point is that the Java developer can provide some data which can convince postgresql to fetch random data for the user. Consider the attached type which is simply an int4 equivalent. Depending on how you define it as passed by value or passed by reference it will or will not work (attached). This looks like it works: jurka=# select '1'::intbyref, '2'::intbyval; intbyref | intbyval ----------+---------- 1 | 2 (1 row) But it doesn't really: jurka=# create table inttest (a intbyref, b intbyval); CREATE TABLE jurka=# insert into inttest values ('1', '2'); INSERT 0 1 jurka=# select * from inttest; a | b ---+------------ 1 | 2139062143 (1 row) You can also get: jurka=# select * from inttest; server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. Kris Jurka --------------010704090706070904030508 Content-Type: text/x-java; name="Int.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Int.java" package types; import java.io.IOException; import java.sql.SQLData; import java.sql.SQLException; import java.sql.SQLInput; import java.sql.SQLOutput; import java.util.logging.Logger; public class Int implements SQLData { private static Logger s_logger = Logger.getAnonymousLogger(); private int m_i; private String m_typeName; public static Int parse(String input, String typeName) throws SQLException { try { int i = Integer.parseInt(input); return new Int(i, typeName); } catch(NumberFormatException e) { throw new SQLException(e.getMessage()); } } public Int() { } public Int(int i, String typeName) { m_i = i; m_typeName = typeName; } public String getSQLTypeName() { return m_typeName; } public void readSQL(SQLInput stream, String typeName) throws SQLException { s_logger.info(typeName + " from SQLInput"); m_i = stream.readInt(); m_typeName = typeName; } public void writeSQL(SQLOutput stream) throws SQLException { s_logger.info(m_typeName + " to SQLOutput"); stream.writeInt(m_i); } public String toString() { s_logger.info(m_typeName + " toString"); return Integer.toString(m_i); } } --------------010704090706070904030508 Content-Type: text/x-sql; name="create_passed_by_value.sql" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="create_passed_by_value.sql" CREATE TYPE intbyval; CREATE FUNCTION intbyval_in(cstring) RETURNS intbyval AS 'UDT[types.Int] input' LANGUAGE java IMMUTABLE STRICT; CREATE FUNCTION intbyval_out(intbyval) RETURNS cstring AS 'UDT[types.Int] output' LANGUAGE java IMMUTABLE STRICT; CREATE FUNCTION intbyval_recv(internal) RETURNS intbyval AS 'UDT[types.Int] receive' LANGUAGE java IMMUTABLE STRICT; CREATE FUNCTION intbyval_send(intbyval) RETURNS bytea AS 'UDT[types.Int] send' LANGUAGE java IMMUTABLE STRICT; CREATE TYPE intbyval ( internallength = 4, input = intbyval_in, output = intbyval_out, receive = intbyval_recv, send = intbyval_send, passedbyvalue ); CREATE TYPE intbyref; CREATE FUNCTION intbyref_in(cstring) RETURNS intbyref AS 'UDT[types.Int] input' LANGUAGE java IMMUTABLE STRICT; CREATE FUNCTION intbyref_out(intbyref) RETURNS cstring AS 'UDT[types.Int] output' LANGUAGE java IMMUTABLE STRICT; CREATE FUNCTION intbyref_recv(internal) RETURNS intbyref AS 'UDT[types.Int] receive' LANGUAGE java IMMUTABLE STRICT; CREATE FUNCTION intbyref_send(intbyref) RETURNS bytea AS 'UDT[types.Int] send' LANGUAGE java IMMUTABLE STRICT; CREATE TYPE intbyref ( internallength = 4, input = intbyref_in, output = intbyref_out, receive = intbyref_recv, send = intbyref_send ); --------------010704090706070904030508--