Package: makedepf90
Version: 3.0.1-3
Severity: normal
Tags: patch
X-Debbugs-Cc: [email protected]
The lexer copies every character of a Fortran string/character literal
into the fixed 8192-byte global buffer string_buf without a bounds check:
lexer.l:92 <str_sq,str_dq>. { *string_buf_ptr++ = yytext[0]; }
A literal longer than MAX_STRING_LEN, including one assembled across
continuation lines, writes past string_buf and corrupts adjacent globals.
Reproducer:
python3 -c "print(' x = \"' + 'A'*9000 + '\"')" > longstr.f90
makedepf90 longstr.f90
Built with -fsanitize=address this reports a global-buffer-overflow write
in yylex at lexer.l:92. Only pathological input triggers it, so the
practical impact on normal builds is nil; hence severity normal.
The buffer only feeds a debug print -- string contents never affect the
emitted dependencies (module and use names are lexed as identifiers) -- so
dropping the overflow characters is safe and leaves the output unchanged.
I verified byte-identical dependency output before and after the patch
across 60 real Fortran sources.
Patch against 3.0.1 (applies cleanly after std23.patch):
--- a/lexer.l
+++ b/lexer.l
@@ -89,7 +89,8 @@
RETURN(UNTERMINATED_STRING);
}
-<str_sq,str_dq>. { *string_buf_ptr++ = yytext[0]; }
+<str_sq,str_dq>. { if (string_buf_ptr < string_buf + MAX_STRING_LEN - 1)
+ *string_buf_ptr++ = yytext[0]; }