pg_read_file() with virtual files returns empty string

Поиск
Список
Период
Сортировка
От Joe Conway
Тема pg_read_file() with virtual files returns empty string
Дата
Msg-id 969b8d82-5bb2-5fa8-4eb1-f0e685c5d736@joeconway.com
обсуждение исходный текст
Ответы Re: pg_read_file() with virtual files returns empty string  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Fwd: PostgreSQL: WolfSSL support
Следующее
От: Ranier Vilela
Дата:
Сообщение: Re: Fwd: PostgreSQL: WolfSSL support