netfilter-match-modules: fix shell-dependent snippet corruption - #152
netfilter-match-modules: fix shell-dependent snippet corruption#152ispyisail wants to merge 1 commit into
Conversation
…t string insert_lines_at() ran the module .c/.y/.l snippets through printf "$lines" to collapse the snippets' escaped %% back to a single %. Shells disagree on how printf handles the unrelated \" also present in those snippets (bash's builtin drops the backslash, dash's doesn't), corrupting emitted files like src/statement.c into invalid C on any system where /bin/sh is bash. Do the %%->% collapse explicitly with sed instead, which is shell-independent.
|
Closing in favour of #154, which supersedes this. This change is correct for the With this merged as-is those come out as a literal That would break the build for everyone, including the dash users who are unaffected today — confirmed live by the reporter in the forum thread (viewtopic.php?t=18408), who hit exactly that error after applying this. #154 carries both halves and has been verified in dash and bash: all 101 spliced files render byte-identically to current dash output, the three Makefile.in continuations are preserved, and a sweep confirms no other backslash-bearing argument reaches |
Fixes a build-from-source failure reported on the forum (asammar, "Compile
from Source Error", https://www.gargoyle-router.com/phpbb/viewtopic.php?t=18408):
compiling
mediatek.filogic(and any other target) fails with errors likesrc/statement.cis not a real source file in this repo -- it's splicedtogether at build time by
integrate_netfilter_modules.shfrom per-modulesnippet files (e.g.
netfilter-match-modules/nftables/weburl/nftables/src_statement.c.1).Those snippets deliberately double up literal
%%(so it survives as asingle
%once inserted into format strings likenft_print(octx, "%%s\\"%%s\\"", ...)).The insertion helper,
insert_lines_at(), did that collapse by handing thesnippet text to
printfas the format string (printf "$lines\n") andrelying on printf's own
%%handling.That also hands the unrelated
\\"already in the snippet to printf'sescape processing, and shells disagree on what an unrecognized
\\"escape does: dash's printf (Debian/Ubuntu's default
/bin/sh) leaves italone, bash's builtin printf (the default
/bin/shon Arch, and othersystems/containers) silently drops the backslash.
build.shinvokes thisscript as
sh $netfilter_patch_script, so the outcome depends entirely onwhat
/bin/shhappens to be -- exactly reproduced locally: same snippetcontent through dash's printf comes out as valid C, through bash's comes
out byte-for-byte matching the forum's reported error.
Fix: do the
%%->%collapse explicitly withsed, and pass thesnippet text to printf as data (
printf '%s\n' "$lines") rather than asa format string. Same fix applied to two more
printf "$var"call sitesfurther down the same script (kernel Makefile var extraction) that had the
identical latent issue, even though their content is less likely to
contain
%%/\\.Verified by extracting the real snippet files for all four affected
modules (weburl, webmon, timerange, bandwidth) and running both the
original and fixed
insert_lines_at()under both bash and dash: theoriginal reproduces the exact reported compile error under bash; the fix
produces identical,
gcc -fsyntax-only-clean C under both shells.