Do not overflow buffer in strncat

This commit is contained in:
Martin Pluskal
2016-09-29 10:39:47 +02:00
committed by Alexey Kopytov
parent cd87db5a30
commit fd04338327

View File

@ -498,11 +498,11 @@ lua_State *sb_lua_new_state(const char *scriptname, int thread_id)
/* first location failed - look in DATA_PATH */
char p[PATH_MAX + 1];
strncpy(p, DATA_PATH LUA_DIRSEP, sizeof(p));
strncat(p, scriptname, sizeof(p));
strncat(p, scriptname, sizeof(p)-strlen(p)-1);
if (!strrchr(scriptname, '.'))
{
/* add .lua extension if there isn't one */
strncat(p, ".lua", sizeof(p));
strncat(p, ".lua", sizeof(p)-strlen(p)-1);
}
if (luaL_loadfile(state, p))