Skip to content
Permalink
Browse files
lsyslog: avoid possible ident corruption
On some systems, openlog() caches the pointer and thus, as the Lua
program runs, ident can get corrupted. The new lsyslog_open() passes a
static copy to openlog() instead of the original Lua string.

Thank you to Sean Conner for pointing out this issue.
  • Loading branch information
ntd committed Jun 7, 2014
1 parent a556e8e commit 95bdbd3
Showing 1 changed file with 9 additions and 1 deletion.
@@ -1,3 +1,5 @@
#include <stdlib.h>
#include <string.h>
#include <syslog.h>

#include <lua.h>
@@ -8,10 +10,16 @@
static int
lsyslog_open(lua_State *L)
{
static char *persistent_ident = NULL;
const char *ident = luaL_checkstring(L, 1);
int facility = luaL_checkinteger(L, 2);

openlog(ident, LOG_PID, facility);
if (persistent_ident != NULL) {
free(persistent_ident);
}

persistent_ident = strdup(ident);
openlog(persistent_ident, LOG_PID, facility);
return 0;
}

0 comments on commit 95bdbd3

Please sign in to comment.