Without this patch, the shell command: awk 'BEGIN { print "x:" for (i = 0; i < 65536; i++) printf "\techo %d\n", i} ' | make -f - incorrectly outputs only "make: 'x' is up to date." * src/commands.c (chop_commands): Report overflow in recipe line count when it occurs, as it's too late to report it later when all evidence of the overflow has vanished. Also, remove stray 'd' in diagnostic.
This overflow check is a bit tricky, as it catches three opportunities for overflow at once. Clearer would be to use Gnulib's idx and stdckdint modules (both small modules easily imported) but that would entail redoing these allocation counts with idx_t which would be a more-extensive change. --- src/commands.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/commands.c b/src/commands.c index e7c0cc87..6434aa7c 100644 --- a/src/commands.c +++ b/src/commands.c @@ -373,6 +373,13 @@ chop_commands (struct commands *cmds) } } + /* Prevent overflow in nlines += 2, in nlines * sizeof (char *), + and in idx++. */ + if (idx == MIN (MIN (UINT_MAX, SIZE_MAX / sizeof (char *)) - 1, + USHRT_MAX)) + ON (fatal, &cmds->fileinfo, + _("Recipe has too many lines (limit %u)"), (unsigned int) idx); + if (idx == nlines) { nlines += 2; @@ -394,9 +401,6 @@ chop_commands (struct commands *cmds) /* Finally, set the corresponding CMDS->lines_flags elements and the CMDS->any_recurse flag. */ - if (nlines > USHRT_MAX) - ON (fatal, &cmds->fileinfo, _("Recipe has too many lines (%ud)"), nlines); - cmds->ncommand_lines = (unsigned short)nlines; cmds->command_lines = lines; -- 2.37.3