netfilter-match-modules: don't use inserted code as a printf format - #154
Open
ispyisail wants to merge 2 commits into
Open
netfilter-match-modules: don't use inserted code as a printf format#154ispyisail wants to merge 2 commits into
ispyisail wants to merge 2 commits into
Conversation
added 2 commits
August 1, 2026 15:06
insert_lines_at() passed snippet contents as printf's format string, so the generated C depended on the shell's printf. Where \" is undefined (bash, coreutils printf) the backslash is dropped and "%s\"%s\"" becomes "%s"%s"", failing to compile. Emit the text literally and drop the %%-escaping the snippets carried for the old behaviour.
The three libnftnl src/Makefile.in inserts wrote '\\' because the old printf-as-format collapsed it to a single backslash. With the text now emitted literally they must carry the single backslash they want, or the generated Makefile gets an escaped backslash instead of a line continuation and automake fails with 'recipe commences before first target'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the "compile from source" failure reported on the forum (t=18408), where
make mediatek.filogicdies with:Root cause
insert_lines_at()inintegrate_netfilter_modules.shspliced snippet files into the real nftables sources with:That passes the snippet as printf's format string, so the generated C depends on the shell's printf implementation. Two things get processed:
%%→%— which is why the snippets were written with%%sto produce%s.\"— undefined in POSIX printf format processing, so implementations differ. dash and busybox ash preserve the backslash; bash and coreutilsprintfdrop it.So
"%%s\"%%s\""becomes"%s\"%s\""(valid) under dash, but"%s"%s""(broken) under bash — a string"%s", a bare%stoken, then"". Hence's' undeclared.This is why it reproduces for some people and not others: it depends entirely on what
/bin/shis. Debian/Ubuntu point it at dash, so it builds; on a distro where/bin/shis bash it fails. Nothing is wrong with the reporter's setup.The blast radius matches the reported errors exactly — the only 4 spliced files containing
\"are weburl (1 line), webmon (1), timerange (3), bandwidth (1), which is precisely the set of failing functions in the log, including timerange's three separate error lines.The fix
insert_lines_at()now usesprintf '%s\n' "$lines", emitting the snippet literally instead of interpreting it.%%escaping they only carried to survive the old behaviour, so they now contain plain, valid C.\"stays as-is — it was always correct C, it was just being mangled in transit.Only files spliced via
action=insertwere touched. Files handled byaction=copyare unchanged, since a%%there is a genuine C printf escape.Verification
Every one of the 101 spliced files was rendered through the old pipeline on a working (dash) system and through the new pipeline under both dash and bash, and compared:
So the generated sources are unchanged for everyone whose build works today, and now identical — rather than broken — for everyone whose
/bin/shis bash. The escape survey behind that claim: across all spliced files the only backslash sequence in use is\"(12 occurrences) and there are no lone%, so%%and\"were the complete set of printf-format dependencies.