【问题标题】:Node: Comments gawk: cmd. line:70: (FILENAME=../doc/m4.texinfo FNR=919) fatal: Invalid content of \{\}: /@tabchar{}/节点:评论 gawk:cmd。 line:70: (FILENAME=../doc/m4.texinfo FNR=919) 致命:\{\} 的内容无效:/@tabchar{}/
【发布时间】:2019-09-25 19:16:36
【问题描述】:

我在修补开源软件易受攻击的问题时遇到了问题,它是在 m4 开源中发现的 CVE-2008-1687。

问题的日志是

cd [build_DIR]/m4/1.4.9-r2/m4-1.4.9/checks && AWK=gawk ./get-them ../doc/m4.texinfo

(....跳过)

节点:评论 gawk:cmd. line:70: (FILENAME=../doc/m4.texinfo FNR=919) 致命:Invalid content of \{\}: /@tabchar{}/

日志说gawk命令执行到m4.texinfo文件的第918行,在第919行出现Invalid content of \{\}: /@tabchar{}/错误。但是,在m4的第919行找不到\{\}内容和/@tabchar{}/字符。纺织信息。 所以,我想知道为什么会发生错误以及如何解决它。

[得到他们]

/^@example$/, /^@end example$/ {
if (seq < 0)
    next;
if ($0 ~ /^@example$/) {
    if (count > 0)
        close (file);
    seq++;
    count++;
    file = sprintf("%03d.%s", count, node);
    printf("dnl @ %s:%d: Origin of test\n"\
        "dnl @ expected status: %d\n"\
        "dnl @ Copyright (C) 2006, 2007 Free Software Foundation\n"\
        "dnl @ This file is free software; the Free Software Foundation\n"\
        "dnl @ gives unlimited permission to copy and/or distribute it\n"\
        "dnl @ with or without modifications, as long as this notice\n"\
        "dnl @ is preserved.\n", FILENAME, NR, status) > file;
    status = 0;
    next;
}
if ($0 ~ /^@end example$/) {
    next;                                             // line 70
}
if ($0 ~ /^\^D$/)
    next;
if ($0 ~ '/^@result\{\}/' || $0 ~ '/^@error\{\}/')
    prefix = "dnl ";
else
    prefix = "";
gsub("@@", "@", $0);
gsub("@{", "{", $0);
gsub("@}", "}", $0);
gsub("@w{ }", " ", $0);
gsub("@tabchar{}", "\t", $0);
printf("%s%s\n", prefix, $0) >> file;

}

[m4.texinfo]

@node 评论 @code{m4} 输入中的@section 注释

@cindex cmets @code{m4} 中的注释通常由字符 @samp{#} 分隔 和换行符。注释分隔符之间的所有字符都被忽略, 但是整个注释(包括分隔符)被传递到 输出---cmets 被@code{m4} 丢弃了@emph{not}。

评论不能嵌套,所以@samp{#} 之后的第一个换行符结束 评论。 begin-comment 字符串的注释效果 可以通过引用来禁止。

@示例

quoted text' #commented text' // 第 919 行

@result{}quoted text # `commented text'

quoting inhibits'#' `cmets'

@result{}引用禁止 # cmets

@end 示例

【问题讨论】:

  • 错误日志是“\{\} : @tabchar{} (\ is missing.)的内容无效

标签: awk


【解决方案1】:

你指出的行是第 70 行:

next;                                             // line 70

显然不是 awk 脚本的第 70 行,因为它不包含错误消息告诉您在第 70 行产生故障的文本:

Invalid content of \{\}: /@tabchar{}/

在这段代码的正则表达式中:

gsub("@tabchar{}", "\t", $0);

{} 是一个 RE 间隔(如 x{3} 表示 x 的 3 次重复) - 它不能为空,我怀疑您希望 {} 无论如何都被视为文字。

看:

$ echo 'foo@tabchar{}bar' | awk 'gsub("@tabchar{}", "\t", $0);'
awk: cmd. line:1: (FILENAME=- FNR=1) fatal: Invalid content of \{\}: /@tabchar{}/

$ echo 'foo@tabchar{}bar' | awk 'gsub("@tabchar\{\}", "\t", $0);'
awk: cmd. line:1: warning: escape sequence `\{' treated as plain `{'
awk: cmd. line:1: warning: escape sequence `\}' treated as plain `}'
awk: cmd. line:1: (FILENAME=- FNR=1) fatal: Invalid content of \{\}: /@tabchar{}/

$ echo 'foo@tabchar{}bar' | awk 'gsub("@tabchar\\{\\}", "\t", $0);'
foo     bar

您需要 2 个转义,因为您在正则表达式上下文中使用字符串,因此 awk 必须首先将字符串转换为正则表达式(使用一组转义),然后将其用作正则表达式(使用剩余的集合转义。使用正则表达式 (/.../) 而不是字符串 ("...") 分隔符围绕正则表达式以避免该问题和其他问题:

$ echo 'foo@tabchar{}bar' | awk 'gsub(/@tabchar\{\}/, "\t", $0);'
foo     bar

您还应该考虑在脚本的其他部分使用正则表达式周围的单引号做什么,例如:

if ($0 ~ '/^@result\{\}/' || $0 ~ '/^@error\{\}/')

我想你可能打算写:

if ($0 ~ /^@result\{\}/ || $0 ~ /^@error\{\}/)

相当于只是:

if (/^@result\{\}/ || /^@error\{\}/)

甚至只是:

if (/^@(result|error)\{\}/)

【讨论】:

  • 非常感谢您的帮助莫顿。 :) 我使用gsub("@tabchar\\{\\}", "\t", $0) 解决了这个问题。嗯..顺便说一句,我修改的代码原本就在那里,在我应用补丁 CVE-2008-1687 之前它运行良好。此外,补丁中没有关于@tabchar{} 的内容。所以,我想知道为什么在修补后出现错误。请您回答一下好吗?
  • wrt "我使用gsub("@tabchar\\{\\}", "\t", $0) 解决了这个问题" - 但我解释了解决它的方法是使用gsub(/@tabchar\{\}/, "\t", $0) 并解释了为什么这是正确的方法,所以为什么不直接做那? wrt“代码在那里并且工作正常,等等。” - 知道你在修补什么,或者这些数字是什么意思,我只能告诉你,我指出的那个代码和脚本中的其他代码有我提到的错误。
  • 好的,抱歉,这个问题问得太多了。我使用gsub(/@tabchar\{\}/, "\t", $0) 进行了修改。再次感谢您的帮助。
猜你喜欢
  • 2016-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-29
  • 2019-12-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多