opt-file.mk revision 1.8 1 # $NetBSD: opt-file.mk,v 1.8 2020/12/22 08:05:08 rillig Exp $
2 #
3 # Tests for the -f command line option.
4
5 # TODO: Implementation
6
7 all: .PHONY
8 all: file-ending-in-backslash
9 all: file-ending-in-backslash-mmap
10 all: file-containing-null-byte
11
12 # Passing '-' as the filename reads from stdin. This is unusual but possible.
13 #
14 # In the unlikely case where a file ends in a backslash instead of a newline,
15 # that backslash is trimmed. See ParseGetLine.
16 #
17 # make-2014.01.01.00.00.00 invoked undefined behavior, reading text from
18 # outside of the file buffer.
19 #
20 # printf '%s' 'VAR=value\' \
21 # | MALLOC_OPTIONS=JA make-2014.01.01.00.00.00 -r -f - -V VAR -dA 2>&1 \
22 # | less
23 #
24 # The debug output shows how make happily uses freshly allocated memory (the
25 # <A5>) and already freed memory ('Z').
26 #
27 # ParseReadLine (1): 'VAR=value\<A5><A5><A5><A5><A5><A5>'
28 # Global:VAR = value\<A5><A5><A5><A5><A5><A5>value\<A5><A5><A5><A5><A5><A5>
29 # ParseReadLine (2): 'alue\<A5><A5><A5><A5><A5><A5>'
30 # ParseDoDependency(alue\<A5><A5><A5><A5><A5><A5>)
31 # make-2014.01.01.00.00.00: "(stdin)" line 2: Need an operator
32 # ParseReadLine (3): '<A5><A5><A5>ZZZZZZZZZZZZZZZZ'
33 # ParseDoDependency(<A5><A5><A5>ZZZZZZZZZZZZZZZZ)
34 #
35 file-ending-in-backslash: .PHONY
36 @printf '%s' 'VAR=value\' \
37 | ${MAKE} -r -f - -V VAR
38
39 # Between parse.c 1.170 from 2010-12-25 and parse.c 1.511 from 2020-12-22,
40 # there was an out-of-bounds write in ParseGetLine, where line_end pointed at
41 # the end of the allocated buffer, in the special case where loadedfile_mmap
42 # had not added the final newline character.
43 file-ending-in-backslash-mmap: .PHONY
44 @printf '%s' 'VAR=value\' > opt-file-backslash
45 @${MAKE} -r -f opt-file-backslash -V VAR
46
47 # If a file contains null bytes, the rest of the line is skipped, and parsing
48 # continues in the next line. Throughout the history of make, the behavior
49 # has changed several times, sometimes knowingly, sometimes by accident.
50 #
51 # echo 'VAR=value' | tr 'l' '\0' > zero-byte.in
52 # printf '%s\n' 'all:' ': VAR=${VAR:Q}' >> zero-byte.in
53 #
54 # for year in $(seq 2003 2020); do
55 # echo $year:
56 # make-$year.01.01.00.00.00 -r -f zero-byte.in
57 # echo "exit status $?"
58 # echo
59 # done 2>&1 \
60 # | sed "s,$PWD/,.,"
61 #
62 # This program generated the following output:
63 #
64 # 2003 to 2007:
65 # exit status 0
66 #
67 # 2008 to 2010:
68 # make: "zero-byte.in" line 1: Zero byte read from file
69 # make: Fatal errors encountered -- cannot continue
70 #
71 # make: stopped in .
72 # exit status 1
73 #
74 # 2011 to 2013:
75 # make: no target to make.
76 #
77 # make: stopped in .
78 # exit status 2
79 #
80 # 2014 to 2020-12-06:
81 # make: "zero-byte.in" line 1: warning: Zero byte read from file, skipping rest of line.
82 # exit status 0
83 #
84 # Since 2020-12-07:
85 # make: "zero-byte.in" line 1: Zero byte read from file
86 # make: Fatal errors encountered -- cannot continue
87 # make: stopped in .
88 # exit status 1
89 file-containing-null-byte: .PHONY
90 @printf '%s\n' 'VAR=value' 'VAR2=VALUE2' \
91 | tr 'l' '\0' \
92 | ${MAKE} -r -f - -V VAR -V VAR2
93
94 all:
95 : Making ${.TARGET}
96