nbd_set_pread_initialize - Man Page

control whether libnbd pre-initializes read buffers


 #include <libnbd.h>

 int nbd_set_pread_initialize (struct nbd_handle *h,
                               bool request);


By default, libnbd will pre-initialize the contents of a buffer passed to calls such as nbd_pread(3) to all zeroes prior to checking for any other errors, so that even if a client application passed in an uninitialized buffer but fails to check for errors, it will not result in a potential security risk caused by an accidental leak of prior heap contents (see CVE-2022-0485 in libnbd-security(3) for an example of a security hole in an application built against an earlier version of libnbd that lacked consistent pre-initialization).  However, for a client application that has audited that an uninitialized buffer is never dereferenced, or which performs its own pre-initialization, libnbd's sanitization efforts merely pessimize performance (although the time spent in pre-initialization may pale in comparison to time spent waiting on network packets).

Calling this function with request set to false tells libnbd to skip the buffer initialization step in read commands.

Return Value

If the call is successful the function returns 0.


On error -1 is returned.

Refer to “ERROR HANDLING” in libnbd(3) for how to get further details of the error.


This function first appeared in libnbd 1.12.

If you need to test if this function is available at compile time check if the following macro is defined:


See Also

nbd_aio_pread(3), nbd_aio_pread_structured(3), nbd_create(3), nbd_get_pread_initialize(3), nbd_pread(3), nbd_pread_structured(3), nbd_set_strict_mode(3), libnbd(3).


Eric Blake

Richard W.M. Jones


This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Referenced By

libnbd(3), NBD(3), nbd_aio_pread(3), nbd_aio_pread_structured(3), nbd_get_pread_initialize(3), nbd_pread(3), nbd_pread_structured(3).

2022-09-27 libnbd-1.15.4