]> git.lizzy.rs Git - minetest.git/commitdiff
Fix safeLoadFile() skipping 2 chars too much from the shebang (#13310)
authorDS <ds.desour@proton.me>
Mon, 27 Mar 2023 18:01:05 +0000 (20:01 +0200)
committerGitHub <noreply@github.com>
Mon, 27 Mar 2023 18:01:05 +0000 (20:01 +0200)
src/script/cpp_api/s_security.cpp

index 09e97100753a6f085e735b283d574179fdf63507..3bf8d10444296674643d39511d5ef07327f9b600 100644 (file)
@@ -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