From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Alexander Turenko <alexander.turenko@tarantool.org>,
tarantool-patches@freelists.org
Subject: [PATCH] lua: escape trigraphs in bundled lua sources
Date: Tue, 18 Jun 2019 15:57:16 +0300 [thread overview]
Message-ID: <e87e997527d3ecb8fb7cf6dc4fe48069f5664861.1560860760.git.alexander.turenko@tarantool.org> (raw)
Built-in modules are bundled into tarantool in the following way. A lua
file from src/lua or src/box/lua is stored as a string literal in a C
file, then built and linked into tarantool. During startup tarantool
calls luaL_loadbuffer() on this string.
When a Lua source is converted to a C literal, proper escaping is
performed. However there is one case, which was not covered: trigraphs.
The patch adds escaping of question mark symbols to avoid matching ??X
sequences as trigraphs by C preprocessor.
The most simple way to check that it works is to apply the following
patch:
| diff --git a/src/lua/string.lua b/src/lua/string.lua
| index 6e12c59ae..2da2dbf4d 100644
| --- a/src/lua/string.lua
| +++ b/src/lua/string.lua
| @@ -425,3 +425,6 @@ string.fromhex = string_fromhex
| string.strip = string_strip
| string.lstrip = string_lstrip
| string.rstrip = string_rstrip
| +string.foo = function()
| + return '??('
| +end
And call the function like so:
| ./src/tarantool -e 'print(string.foo()) os.exit()'
If it printfs `??(`, then everything is okay. If it prints `[`, then
`??(` was preprocessed as the trigraph.
We hit this problem when tried to bundle luarocks-3: it contains
"^(.-)(%??)$" regexp, where `??)` was interpreted as `]`. Debug build or
a build with -DENABLE_WERROR reports an error in the case, but usual
RelWithDebInfo build passes (with -Wtrigraphs warnings) and can show
this unexpected behaviour.
Fixes #4291.
---
https://github.com/tarantool/tarantool/issues/4291
https://github.com/tarantool/tarantool/tree/Totktonada/gh-4291-fix-bundled-lua-escaping
| 2 ++
1 file changed, 2 insertions(+)
--git a/extra/txt2c.c b/extra/txt2c.c
index e1bad0825..3f701d611 100644
--- a/extra/txt2c.c
+++ b/extra/txt2c.c
@@ -70,6 +70,8 @@ int main(int argc, char** argv) {
case '\r': fputs("\\r", out); break;
case '\\': fputs("\\\\", out); break;
case '\"': fputs("\\\"", out); break;
+ /* Don't interpret ??X as a trigraph. */
+ case '?': fputs("\\\?", out); break;
default: fputc(c, out); break;
}
}
--
2.21.0
next reply other threads:[~2019-06-18 12:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-18 12:57 Alexander Turenko [this message]
2019-06-18 17:00 ` Vladimir Davydov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e87e997527d3ecb8fb7cf6dc4fe48069f5664861.1560860760.git.alexander.turenko@tarantool.org \
--to=alexander.turenko@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=vdavydov.dev@gmail.com \
--subject='Re: [PATCH] lua: escape trigraphs in bundled lua sources' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox