[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [PATCH v2 05/13] libdpkg: fix compress_cat to read/write to arbitrary fds



Hi!

On Sat, 2009-10-24 at 17:42:52 -0500, Jonathan Nieder wrote:
> The compress_cat() code had a hidden assumption that fd_in is 0
> and fd_out is 1.  This is a bug waiting to happen.  But luckily,
> all callers do use those values, so it is harmless.

> diff --git a/lib/dpkg/compression.c b/lib/dpkg/compression.c
> index c80a9b1..f1b6836 100644
> --- a/lib/dpkg/compression.c
> +++ b/lib/dpkg/compression.c
> @@ -70,8 +70,8 @@ fd_fd_filter(int fd_in, int fd_out,
>    \
>    strncpy(combuf, "w9", sizeof(combuf)); \
>    combuf[1] = compression; \
> -  zfile = zdopen(1, combuf); \
> -  while ((actualread = read(0, buffer, sizeof(buffer))) > 0) { \
> +  zfile = zdopen(fd_out, combuf); \
> +  while ((actualread = read(fd_in, buffer, sizeof(buffer))) > 0) { \
>      if (actualread < 0) { \
>        if (errno == EINTR) \
>          continue; \

Nice catch! Applied.

thanks,
guillem


Reply to: