make-w32
[Top][All Lists]
Advanced

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

[make-3.80] bug in process_begin() [subproc.c]


From: Christoph Schulz
Subject: [make-3.80] bug in process_begin() [subproc.c]
Date: Wed, 11 Feb 2004 13:34:49 +0100

Hello!

--Considering make 3.80 Release and latest CVS sources--

The implementation of the function process_begin() in subproc.c
is somewhat buggy. At different positions it returns with an
error code without reliably setting pproc->last_err to a
value != 0. This is fatal, as process_wait_for_any_private()
depends on it in line 79.

The bug occurs in process_wait_for_any_private() in line 95,
where 'proc_array[which]' points to an invalid entry. This is
because the condition in the loop in line 79 was not satisfied,
having 'i == proc_index.' Because fake_exits_pending is not zero
(process_begin() returned != 0, so process_easy() incremented
fake_exits_pending in line 1195), the code in line 90 is
executed, assigning 'i' to 'which', which finally leads to the
out-of-bound array index.

The positions in process_begin() to be fixed are:
- line 422: regardless of the failure of the condition in line
  418, GetLastError() may return zero (for example, if ReadFile()
  returns 0 or 1 bytes read).
- line 471: explicit setting of last_err to 0
- line 478: explicit setting of last_err to 0
- line 506: no setting of last_err

It's possible to trigger the bug with the following makefile:


all:
 rm -f xyz
 touch xyz
 xyz


Since 'xyz' will be a file of zero length, the code in line 422
will behave erratically, causing the bug to occur.

There are more than one possibility to fix the bug. The simpliest
would be to fix process_easy() to set last_err to a non-zero
value if process_begin() failed. Patch is appended.

And yet an issue: w32err.c: line 20: appending a '\n' to the
message is needed for the case when FormatMessage() cannot map
the error code. Otherwise, 'make' prints two error messages
without an intermediate line break.

Regards,
  Christoph


Attachment: make-w32-exec.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]