原文
| ||||||||||
| ||||||||||
![]() |
原始链接: https://news.ycombinator.com/item?id=43646698
Hacker News 讨论主要围绕类 Unix 系统中的 Shebang(`#!`)机制展开。一位用户提到了一个“空字节攻击”,其中空字节可以终止 Shebang 行,从而允许以非标准方式向解释器传递额外参数。另一位用户回忆起过去由于来自 Windows 系统的 Shebang 行中包含回车符(`
| ||||||||||
| ||||||||||
![]() |
It's possible to have a scripting language support extra command line arguments after the null byte, which is less disruptive to the syntax than recognizing arguments from a second line.
I.e.
Or On some OS's, you only get one arg: everything after the space, to the end of the line, is one argument.When we stick a there, that argument stops there; but our interpreter can read the whole line including the up to the and then extract additional arguments between and
https://www.nongnu.org/txr/txr-manpage.html#N-74C247FD
The interpreter could get the arguments in other ways, like from a second line after the hash bang line. But with the null hack, all the processing revolves around just the one hash bang line. You can retrofit this logic into an interpreter that already knows how to ignore the hash bang line, without doing any work beyond getting it to load the line properly with the embedded nul, and extract the arguments. You dont have to alter the syntax to specially recognize a hash bang continuation line.
reply