pg_read_file() with virtual files returns empty string - Mailing list pgsql-hackers

From Joe Conway
Subject pg_read_file() with virtual files returns empty string
Date
Msg-id 969b8d82-5bb2-5fa8-4eb1-f0e685c5d736@joeconway.com
Whole thread Raw
Responses Re: pg_read_file() with virtual files returns empty string
List pgsql-hackers
Since pg11 pg_read_file() and friends can be used with absolute paths as long as
the user is superuser or explicitly granted the role pg_read_server_files.

I noticed that when trying to read a virtual file, e.g.:

  SELECT pg_read_file('/proc/self/status');

the returned result is a zero length string.

However this works fine:

  SELECT pg_read_file('/proc/self/status', 127, 128);

The reason for that is pg_read_file_v2() sets bytes_to_read=-1 if no offset and
length are supplied as arguments when it is called. It passes bytes_to_read down
to read_binary_file().

When the latter function sees bytes_to_read < 0 it tries to read the entire file
by getting the file size via stat, which returns 0 for a virtual file size.

The attached patch fixes this for me. I think it ought to be backpatched through
pg11.

Comments?

Joe
--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development

Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Fwd: PostgreSQL: WolfSSL support
Next
From: Ranier Vilela
Date:
Subject: Re: Fwd: PostgreSQL: WolfSSL support