diff options
author | Emil Renner Berthing <esmil@mailme.dk> | 2013-01-12 02:27:51 +0100 |
---|---|---|
committer | Emil Renner Berthing <esmil@mailme.dk> | 2013-01-12 14:56:14 +0100 |
commit | d5c4013e1c60c5801545632b99a4409c45f74d62 (patch) | |
tree | 2b324291dbe23678498ee9dd6d86ed03a0123b74 | |
parent | 13c16668dceefaf5072527df5484abf81282eed5 (diff) | |
download | lem-d5c4013e1c60c5801545632b99a4409c45f74d62.tar.gz lem-d5c4013e1c60c5801545632b99a4409c45f74d62.tar.xz lem-d5c4013e1c60c5801545632b99a4409c45f74d62.zip |
io: use memcpy to copy unix socket path
This allows for unix sockets in the abstract namespace
on Linux. Eg.:
local conn, err = io.unix.connect('\0/org/freedesktop/systemd1/notify')
-rw-r--r-- | lem/io/unix.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lem/io/unix.c b/lem/io/unix.c index a7464f0..9e3ce90 100644 --- a/lem/io/unix.c +++ b/lem/io/unix.c @@ -39,7 +39,7 @@ unix_connect_work(struct lem_async *a) } addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, u->path); + memcpy(addr.sun_path, u->path, u->len+1); if (connect(sock, (struct sockaddr *)&addr, offsetof(struct sockaddr_un, sun_path) + u->len)) { @@ -103,7 +103,7 @@ unix_connect(lua_State *T) const char *path = luaL_checklstring(T, 1, &len); struct unix_create *u; - if (len >= UNIX_PATH_MAX) /* important. strcpy is used later */ + if (len >= UNIX_PATH_MAX) return luaL_argerror(T, 1, "path too long"); u = lem_xmalloc(sizeof(struct unix_create)); @@ -131,7 +131,7 @@ unix_listen_work(struct lem_async *a) } addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, u->path); + memcpy(addr.sun_path, u->path, u->len+1); if (bind(sock, (struct sockaddr *)&addr, offsetof(struct sockaddr_un, sun_path) + u->len)) { @@ -217,7 +217,7 @@ unix_listen(lua_State *T) int backlog = (int)luaL_optnumber(T, 2, MAXPENDING); struct unix_create *u; - if (len >= UNIX_PATH_MAX) /* important. strcpy is used later */ + if (len >= UNIX_PATH_MAX) return luaL_argerror(T, 1, "path too long"); u = lem_xmalloc(sizeof(struct unix_create)); |