dbTalk Databases Forums  

[BUGS] Reading from a read-only BLOB is allowed

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] Reading from a read-only BLOB is allowed in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gonzalo Paniagua Javier
 
Posts: n/a

Default [BUGS] Reading from a read-only BLOB is allowed - 08-16-2003 , 08:39 PM






--=-Qy4k09ws5Lp3vFHlXVas
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi!

It seems that postgres allows writing to a read-only blob opened like:

fd = lo_open (cnc, oid, INV_READ);

I've attached a simple test case and the Makefile to build it.

I'm using postgresql 7.3.3 (7.3.3-1 is the debian package version).

Is that the intended behaviour or is it a bug?

-Gonzalo

P.S.: please, CC me as I'm not suscribed to this list. Thanks.

--
Gonzalo Paniagua Javier <gonzalo (AT) gnome-db (DOT) org>
http://www.gnome-db.org/~gonzalo/




--=-Qy4k09ws5Lp3vFHlXVas
Content-Disposition: attachment; filename=inversion-bug.c
Content-Type: text/x-c; name=inversion-bug.c; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

#include <string.h>
#include <libpq-fe.h>
#include <libpq/libpq-fs.h>

static char *conn_string =
"dbname=test user=gonzalo password=password hostaddr=127.0.0.1";

int
main ()
{
PGconn *cnc;
PGresult *res;
int oid, fd;
char *the_string = "The String";
char *other_str = " ";
int written;
int result = 0;

cnc = PQconnectdb (conn_string);
if (PQstatus (cnc) != CONNECTION_OK) {
printf ("Error connecting: %s\n", PQerrorMessage (cnc));
return -1;
}

res = PQexec (cnc, "begin");
PQclear(res);

oid = lo_creat (cnc, INV_READ | INV_WRITE); /* Don't care if only one is set */
fd = lo_open (cnc, oid, INV_READ);
if (fd < 0) {
printf ("Error opening BLOB: %s\n", PQerrorMessage (cnc));
return -1;
}

written = lo_write (cnc, fd, the_string, strlen (the_string));
if (written >= 0) {
printf ("ERROR: I was able to write %d bytes.\n", written);
result = 1;
} else {
printf ("It worked! %s\n", PQerrorMessage (cnc));
}

lo_close (cnc, fd);
lo_unlink (cnc, oid);

res = PQexec (cnc, "end");
PQclear (res);
PQfinish (cnc);

return result;
}


--=-Qy4k09ws5Lp3vFHlXVas
Content-Disposition: attachment; filename=Makefile
Content-Type: text/x-makefile; name=Makefile; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

CC=gcc
CFLAGS = -g -I/usr/include/postgresql
LDFLAGS = -lpq

inversion-bug: inversion-bug.o

inversion-bug.o: inversion-bug.c

clean:;
rm -f *.o inversion-bug *~


--=-Qy4k09ws5Lp3vFHlXVas
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

--=-Qy4k09ws5Lp3vFHlXVas--


Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] Reading from a read-only BLOB is allowed - 08-17-2003 , 01:02 AM






Gonzalo Paniagua Javier <gonzalo (AT) gnome-db (DOT) org> writes:
Quote:
It seems that postgres allows writing to a read-only blob opened like:
fd = lo_open (cnc, oid, INV_READ);
AFAICS from the code, INV_READ/WRITE attached to lo_open only determine
the kind of lock taken on the LO (shared or exclusive). Not sure
whether it's a bug to prohibit the other kind of access or not.

Note that there's no "security" issue here, since anyone is allowed to
write any LO anyway.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.