aboutsummaryrefslogtreecommitdiff
path: root/src/unixstream.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/unixstream.c')
-rw-r--r--src/unixstream.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/unixstream.c b/src/unixstream.c
index 02aced9..89a8776 100644
--- a/src/unixstream.c
+++ b/src/unixstream.c
@@ -33,8 +33,8 @@ static int meth_getstats(lua_State *L);
33static int meth_setstats(lua_State *L); 33static int meth_setstats(lua_State *L);
34static int meth_getsockname(lua_State *L); 34static int meth_getsockname(lua_State *L);
35 35
36static const char *unixstream_tryconnect(p_unix un, const char *path); 36static const char *unixstream_tryconnect(p_unix un, const char *path, size_t len);
37static const char *unixstream_trybind(p_unix un, const char *path); 37static const char *unixstream_trybind(p_unix un, const char *path, size_t len);
38 38
39/* unixstream object methods */ 39/* unixstream object methods */
40static luaL_Reg unixstream_methods[] = { 40static luaL_Reg unixstream_methods[] = {
@@ -181,13 +181,12 @@ static int meth_accept(lua_State *L) {
181/*-------------------------------------------------------------------------*\ 181/*-------------------------------------------------------------------------*\
182* Binds an object to an address 182* Binds an object to an address
183\*-------------------------------------------------------------------------*/ 183\*-------------------------------------------------------------------------*/
184static const char *unixstream_trybind(p_unix un, const char *path) { 184static const char *unixstream_trybind(p_unix un, const char *path, size_t len) {
185 struct sockaddr_un local; 185 struct sockaddr_un local;
186 size_t len = strlen(path);
187 int err; 186 int err;
188 if (len >= sizeof(local.sun_path)) return "path too long"; 187 if (len >= sizeof(local.sun_path)) return "path too long";
189 memset(&local, 0, sizeof(local)); 188 memset(&local, 0, sizeof(local));
190 strcpy(local.sun_path, path); 189 memcpy(local.sun_path, path, len);
191 local.sun_family = AF_UNIX; 190 local.sun_family = AF_UNIX;
192#ifdef UNIX_HAS_SUN_LEN 191#ifdef UNIX_HAS_SUN_LEN
193 local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) 192 local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len)
@@ -204,8 +203,9 @@ static const char *unixstream_trybind(p_unix un, const char *path) {
204 203
205static int meth_bind(lua_State *L) { 204static int meth_bind(lua_State *L) {
206 p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); 205 p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1);
207 const char *path = luaL_checkstring(L, 2); 206 size_t len;
208 const char *err = unixstream_trybind(un, path); 207 const char *path = luaL_checklstring(L, 2, &len);
208 const char *err = unixstream_trybind(un, path, len);
209 if (err) { 209 if (err) {
210 lua_pushnil(L); 210 lua_pushnil(L);
211 lua_pushstring(L, err); 211 lua_pushstring(L, err);
@@ -234,14 +234,13 @@ static int meth_getsockname(lua_State *L)
234/*-------------------------------------------------------------------------*\ 234/*-------------------------------------------------------------------------*\
235* Turns a master unixstream object into a client object. 235* Turns a master unixstream object into a client object.
236\*-------------------------------------------------------------------------*/ 236\*-------------------------------------------------------------------------*/
237static const char *unixstream_tryconnect(p_unix un, const char *path) 237static const char *unixstream_tryconnect(p_unix un, const char *path, size_t len)
238{ 238{
239 struct sockaddr_un remote; 239 struct sockaddr_un remote;
240 int err; 240 int err;
241 size_t len = strlen(path);
242 if (len >= sizeof(remote.sun_path)) return "path too long"; 241 if (len >= sizeof(remote.sun_path)) return "path too long";
243 memset(&remote, 0, sizeof(remote)); 242 memset(&remote, 0, sizeof(remote));
244 strcpy(remote.sun_path, path); 243 memcpy(remote.sun_path, path, len);
245 remote.sun_family = AF_UNIX; 244 remote.sun_family = AF_UNIX;
246 timeout_markstart(&un->tm); 245 timeout_markstart(&un->tm);
247#ifdef UNIX_HAS_SUN_LEN 246#ifdef UNIX_HAS_SUN_LEN
@@ -259,8 +258,9 @@ static const char *unixstream_tryconnect(p_unix un, const char *path)
259static int meth_connect(lua_State *L) 258static int meth_connect(lua_State *L)
260{ 259{
261 p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); 260 p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1);
262 const char *path = luaL_checkstring(L, 2); 261 size_t len;
263 const char *err = unixstream_tryconnect(un, path); 262 const char *path = luaL_checklstring(L, 2, &len);
263 const char *err = unixstream_tryconnect(un, path, len);
264 if (err) { 264 if (err) {
265 lua_pushnil(L); 265 lua_pushnil(L);
266 lua_pushstring(L, err); 266 lua_pushstring(L, err);