lib/socket: support reading string with null bytes