From 2180dc14ef802961d50d5e5f7fccd2d3a2b9f647 Mon Sep 17 00:00:00 2001 From: DS Date: Mon, 27 Mar 2023 20:01:05 +0200 Subject: [PATCH] Fix safeLoadFile() skipping 2 chars too much from the shebang (#13310) --- src/script/cpp_api/s_security.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp index 09e971007..3bf8d1044 100644 --- a/src/script/cpp_api/s_security.cpp +++ b/src/script/cpp_api/s_security.cpp @@ -457,11 +457,10 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path, const char size_t start = 0; int c = std::getc(fp); if (c == '#') { - // Skip the first line - while ((c = std::getc(fp)) != EOF && c != '\n') {} - if (c == '\n') - std::getc(fp); - start = std::ftell(fp); + // Skip the shebang line (but keep line-ending) + while (c != EOF && c != '\n') + c = std::getc(fp); + start = std::ftell(fp) - 1; } // Read the file