Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <BLU436-SMTP1606516841D7B5F6E0446DCC0B10@phx.gbl>
Date: Tue, 23 Sep 2014 20:14:51 -1000
From: Scott Valentine <scottvalen@...mail.com>
To: musl@...ts.openwall.com
CC: Szabolcs Nagy <nsz@...t70.net>, Justin Cormack <justin@...cialbusservice.com>
Subject: Re: LUA + musl, garbage collection issue?

On Wednesday, September 24, 2014 07:50:01 AM Szabolcs Nagy wrote:
> * Scott Valentine <scottvalen@...mail.com> [2014-09-23 19:25:47 -1000]:
> > 
> > In any case, this has been a nasty issue to track down. I have surely traced it to the following code block in luci (by process of elimination):
> > 
> >         local fp
> >         luci.http.setfilehandler(
> >                 function(meta, chunk, eof)
> >                         if not fp then
> >                                 if meta and meta.name == "image" then
> >                                         fp = io.open(image_tmp, "w")
> >                                 else
> >                                         fp = io.popen(restore_tmp, "w")
> >                                 end
> >                         end
> >                         if chunk then
> >                                 fp:write(chunk)
> >                         end
> >                         if eof then
> >                                 fp:close()
> >                         end
> >                 end
> >         )
> > 
> > 
> > Here, "chunk" is a 2048 byte string, and the library calls are to nixio:
> > 
> 
> are you sure the nixio function is called?
> 
> if fp is not set then io.open is called which should
> use libc fopen, so fp:write should be a wrapper around
> fwrite

> if the code really calls the nixio function below then
> there is no stdio involved, it directly writes to an fd

You are correct... My brain must be getting tired. 
 
> > static int nixio_file_write(lua_State *L) {
> >         int fd = nixio__checkfd(L, 1);
> >         size_t len;
> >         ssize_t sent;
> >         const char *data = luaL_checklstring(L, 2, &len);
> > 
> >         if (lua_gettop(L) > 2) {
> >                 int offset = luaL_optint(L, 3, 0);
> >                 if (offset) {
> >                         if (offset < len) {
> >                                 data += offset;
> >                                 len -= offset;
> >                         } else {
> >                                 len = 0;
> >                         }
> >                 }
> > 
> >                 unsigned int wlen = luaL_optint(L, 4, len);
> >                 if (wlen < len) {
> >                         len = wlen;
> >                 }
> >         }
> > 
> >         do {
> >                 sent = write(fd, data, len);
> >         } while(sent == -1 && errno == EINTR);
> >         if (sent >= 0) {
> >                 lua_pushinteger(L, sent);
> >                 return 1;
> >         } else {
> >                 return nixio__perror(L);
> >         }
> > }
> > 
> 
> 
> > When I have time, I'll do a build against eglibc with a reduced BUFSIZ = 1024 (musl's default) and see if the problem is reproduced.
> > 
> 
> i think you should try to reproduce the bug with a minimal
> test-case where either stdio (io.*) is called or nixio only

Yes, now that you've pointed out the above, I have something I can work with. I should be able to write a pure lua script to try and reproduce the problem.

-Scott V.

-- 

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.