Fix safeLoadFile() skipping 2 chars too much from the shebang (#13310)

This commit is contained in:
DS 2023-03-27 20:01:05 +02:00 committed by GitHub
parent baf99f826c
commit 2180dc14ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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