Bug 1759

Summary: dce httpd example stops working with big files (~1MB)
Product: dce Reporter: tedc75
Component: otherAssignee: Hajime Tazaki <tazaki>
Status: CLOSED FIXED    
Severity: major CC: ns-bugs, tedc75
Priority: P3    
Version: unspecified   
Hardware: All   
OS: Linux   
Attachments: writev() degraded proposed fix

Description tedc75 2013-09-10 12:46:18 EDT
When running the provided example dce-httpd
./waf --run dce-httpd 
this only works with a small file. Any large file results in SIGSEGV.
 Command ['/home/ted/work/ns3/dce/dce/source/ns-3-dce/build/myscripts/httpd/bin/dce-httpd'] terminated with signal SIGSEGV. Run it under a debugger to get more information (./waf --run <program> --command-template="gdb --args %s <args>").

Running with dce-ns3-1.1 , not the dce-linux-1.1 which cannot work due to:
msg="fcntl not implemented on socket", file=../model/linux-socket-fd.cc, line=183
NB: despite the wscript want to build it only for linux kernel stack
(I commented the line:  if bld.env['KERNEL_STACK']:  to compile it)

Bug reproducibility: always. Just add the following code:
FILE *fp=fopen("files-0/index.html", "wb"); int i; for (i=0; i<500000; i++) {fprintf(fp,"%d\n",i);}fclose(fp);
in source/ns-3-dce/myscripts/httpd/dce-httpd.cc after line 51:
//  CreateFiles ();

NB: the bug is present also if a big file named index.html is directly added to the folder files-0

Already debugged a bit, but could not solve it:
- it is not an issue with wget (tried also with a simple C program to send HTTP request and write down the result, same error)
- thttpd 2.25b (dce version) works perfectly if run standalone with wget 1.14 (dce version) on the same big file.
- also compiled thttpd with -U_FORTIFY_SOURCE (not mentioned in source/ns-3-dce/myscripts/httpd/README)
- also checked thttpd with valgrind, replaced overlapping strcpy() calls (which might have undefined behavior) with  memmove() patch: see http://marc.info/?l=thttpd&m=107035015925670&w=2 : no valgrind warning but still not working
Comment 1 Hajime Tazaki 2013-09-11 02:36:54 EDT
thanks for reporting.

what distribution (of Linux, e.g. Ubuntu 12.XX, 32bits or 64bits) are you using ?
Comment 2 tedc75 2013-09-11 02:50:45 EDT
Ubuntu 12.04.1 LTS, 64bits

By the way with simpler HTTP server such as this very simple "toy server" like https://github.com/stackbox/code/tree/master/tinyhttpd-0.1.0
everything works well even with big files.
So probably there is some usage of socket functions by thttpd-2.25b that creates problems. Unfortunately I was not so good to debug it with the gdb command.
Comment 3 Hajime Tazaki 2013-09-11 03:01:13 EDT
(In reply to comment #2)
> Ubuntu 12.04.1 LTS, 64bits

thanks. I will try to reproduce it.

> By the way with simpler HTTP server such as this very simple "toy server" like
> https://github.com/stackbox/code/tree/master/tinyhttpd-0.1.0
> everything works well even with big files.
> So probably there is some usage of socket functions by thttpd-2.25b that
> creates problems. Unfortunately I was not so good to debug it with the gdb
> command.

thanks for the info.
just curious: did you rung tinyhttpd over DCE ?
Comment 4 Hajime Tazaki 2013-09-25 03:06:53 EDT
fixed in changeset 98f8c21e069f

http://code.nsnam.org/ns-3-dce/rev/98f8c21e069f

the root cause is not by thttpd itself, but dce_writev () implemented in ns-3-dce had an issue of buffer overflow.
Comment 5 Hajime Tazaki 2013-11-05 15:48:46 EST
writev has degraded by the changeset 98f8c21e069f. will fix asap.
Comment 6 Hajime Tazaki 2013-11-05 15:54:10 EST
Created attachment 1698 [details]
writev() degraded proposed fix
Comment 7 Hajime Tazaki 2013-11-09 10:40:55 EST
fixed again on changeset: 10f560475c48
Comment 8 tedc75 2013-11-12 03:00:53 EST
(In reply to comment #7)
> fixed again on changeset: 10f560475c48

In fact the patch solves the bug. Many thanks and sorry for the late answer!
Comment 9 tedc75 2013-11-12 03:08:12 EST
(In reply to comment #3)
> (In reply to comment #2)
> > Ubuntu 12.04.1 LTS, 64bits
> 
> thanks. I will try to reproduce it.
> 
> > By the way with simpler HTTP server such as this very simple "toy server" like
> > https://github.com/stackbox/code/tree/master/tinyhttpd-0.1.0
> > everything works well even with big files.
> > So probably there is some usage of socket functions by thttpd-2.25b that
> > creates problems. Unfortunately I was not so good to debug it with the gdb
> > command.
> 
> thanks for the info.
> just curious: did you rung tinyhttpd over DCE ?

(In reply to comment #3)
> (In reply to comment #2)
> > Ubuntu 12.04.1 LTS, 64bits
> 
> thanks. I will try to reproduce it.
> 
> > By the way with simpler HTTP server such as this very simple "toy server" like
> > https://github.com/stackbox/code/tree/master/tinyhttpd-0.1.0
> > everything works well even with big files.
> > So probably there is some usage of socket functions by thttpd-2.25b that
> > creates problems. Unfortunately I was not so good to debug it with the gdb
> > command.
> 
> thanks for the info.
> just curious: did you rung tinyhttpd over DCE ?

Yes: just compile with (e.g.):
gcc -fPIC -U_FORTIFY_SOURCE -Wall -o httpd httpd.c -pie -lpthread
Also, to simplify things, I removed the option to run "cgi" scripts in the httpd.c source code: from line 118 on, just leave the
serve_file(client, path);  call, and remove the check if the file is executable etc.
Thanks for your help!