0

I'm developing an application for an embedded platform, namely DM385 by TI running arago linux.

I've encountered a strange problem when uploading files larger than 3-4 MB via http.

Sometimes the upload works well, other times the file gets uploaded but the data gets corrupted with the HTTP header appearing in the middle of the file's binary data.

Other times, I get a glibc() error (malloc or free) or SIGSEGV and boa crashes.

When using smaller files, like 1MB or less, everything works well. I've tried to debug the issue by adding vairous debug prints throughout the program's flow. This in turn really slowed down the server's operation and temporarily resolved the problem - the file upload worked well every single time.

It seems like there is some kind of buffer underrun occuring in one of the file descriptors being used during the data transfer but I can't really point my finger on anything specific.

Could somebody share some knowledge regarding this issue or similar ones?

[updated from comment:]

The warnings during build:

boa.c: In function 'main':
boa.c:290: warning: passing argument 4 of 'pthread_create' makes pointer from integer without a cast
boa.c:292: warning: implicit declaration of function 'onvif_dbg'
boa.c: In function 'create_server_socket_udp_hello':
boa.c:376: warning: unused variable 'one'
boa.c: At top level:
boa.c:374: warning: 'create_server_socket_udp_hello' defined but not used
buffer.c: In function 'req_flush':
buffer.c:219: warning: implicit declaration of function 'onvif_dbg'
cgi.c: In function 'uri_decoding':
cgi.c:329: warning: pointer targets in passing argument 1 of 'ascii_to_hex' differ in signedness
config.c: In function 'read_config_files':
config.c:294: warning: implicit declaration of function 'onvif_trace'
request.c: In function 'uri_mpeg4':
request.c:3327: warning: implicit declaration of function 'onvif_dbg'
request.c: In function 'process_requests':
request.c:4730: warning: suggest parentheses around assignment used as truth value
request.c: At top level:
request.c:49: warning: 'sts' defined but not used
In file included from response.c:26:
/home/user/IPNC_RDK/Source/ipnc_rdk/../ipnc_rdk/ipnc_app/interface/inc/system_default.h:16:1: warning: "IPNC_DM385" redefined
<command-line>: warning: this is the location of the previous definition
In file included from select.c:27:
onvif.h:33:12: warning: missing whitespace after the macro name
select.c: In function 'probe_thr':
select.c:46: warning: implicit declaration of function 'GetSysInfo'
select.c:46: warning: initialization makes pointer from integer without a cast
select.c:51: warning: control reaches end of non-void function
select.c: In function 'select_loop':
select.c:66: warning: implicit declaration of function 'pthread_create'
select.c:68: warning: implicit declaration of function 'onvif_dbg'
alk
  • 69,737
  • 10
  • 105
  • 255
eliba
  • 140
  • 10
  • If you were using Java, I would say that might be a race condition. Maybe the server is running out of memory? – Mauren Mar 13 '14 at 12:22
  • 1
    [boa](http://www.boa.org/news.html) is not very active (last release in 2005). Did you consider switching to another webserver, like [lighttpd](http://lighttpd.net), or using some HTTP server library in your app (e.g. [libonion](http://www.coralbits.com/libonion/) ...)? – Basile Starynkevitch Mar 13 '14 at 12:28
  • Normally I'd try that, but the boa source package I'm working with contains numerous valuable additions integrated into it that are a must for our application. I'm afraid that integrating those modules into a different web server would take too much work. – eliba Mar 13 '14 at 15:10
  • Do the sources compile without warnings when passing `-Wall -Wextra -pedantic` to the compiler? – alk Mar 13 '14 at 15:39
  • No, there are some warnings. Any specific ones I should look out for? – eliba Mar 13 '14 at 17:45
  • Here are the actual warnings that appear during compilation with the above flags: http://pastebin.com/fAvGy0TP – eliba Mar 16 '14 at 13:36
  • @eliba were you able to find the problem? I am having a similar issue with the dm368. – jjcf89 Apr 22 '14 at 16:45
  • unfortunately, the toolchain I'm using, Code Sourcery Lite, does not not offer a version of glibc with debug symbols, so I was unable to run valgrind to find the problem. I've decided to use lighttpd to implement the feature that requires file uploading (firmware update). – eliba Apr 23 '14 at 17:29

1 Answers1

1

The best would be to fix all warnings.

However (the comments refer to the warning above them):

boa.c: In function 'main':
boa.c:290: warning: passing argument 4 of 'pthread_create' makes pointer from integer without a cast

Inspect this one, it might be fatal.

boa.c:292: warning: implicit declaration of function 'onvif_dbg'

Fix this.

boa.c: In function 'create_server_socket_udp_hello':
boa.c:376: warning: unused variable 'one'

Not nice, but harmless.

boa.c: At top level:
boa.c:374: warning: 'create_server_socket_udp_hello' defined but not used

Not nice, but harmless.

buffer.c: In function 'req_flush':
buffer.c:219: warning: implicit declaration of function 'onvif_dbg'

Fix this.

cgi.c: In function 'uri_decoding':
cgi.c:329: warning: pointer targets in passing argument 1 of 'ascii_to_hex' differ in signedness

Inspect this one, it might be fatal.

config.c: In function 'read_config_files':
config.c:294: warning: implicit declaration of function 'onvif_trace'

Fix this.

request.c: In function 'uri_mpeg4':
request.c:3327: warning: implicit declaration of function 'onvif_dbg'

Fix this.

request.c: In function 'process_requests':
request.c:4730: warning: suggest parentheses around assignment used as truth value

Inspect this one, it might be fatal.

request.c: At top level:
request.c:49: warning: 'sts' defined but not used

Not nice, but harmless.

In file included from response.c:26:
/home/user/IPNC_RDK/Source/ipnc_rdk/../ipnc_rdk/ipnc_app/interface/inc/system_default.h:16:1: warning: "IPNC_DM385" redefined
<command-line>: warning: this is the location of the previous definition
In file included from select.c:27:

Inspect this one, it might be fatal.

onvif.h:33:12: warning: missing whitespace after the macro name

Inspect this one, it might be fatal.

select.c: In function 'probe_thr':
select.c:46: warning: implicit declaration of function 'GetSysInfo'

Fix this.

select.c:46: warning: initialization makes pointer from integer without a cast

Fix this.

select.c:51: warning: control reaches end of non-void function

Fix this.

select.c: In function 'select_loop':
select.c:66: warning: implicit declaration of function 'pthread_create'

Fix this.

select.c:68: warning: implicit declaration of function 'onvif_dbg'

Fix this.

alk
  • 69,737
  • 10
  • 105
  • 255
  • 1
    Thanks for your very detailed feedback. I will look into those and see if it helps! Will report back with results. – eliba Mar 18 '14 at 08:53
  • You are welcome. If all warnings had been properly fixed and you still observe "strange" behaviour, than go for running the application using a memory checker like Valgrind (http://valgrind.org), which might shed some light on subtile bug(s) like reading/writing invalid memory, which could easily cause crashes on a random base. – alk Mar 18 '14 at 09:35
  • I have actually looked at valgrind already, though right now I'm experiencing problems running it since I only have a stripped version of glibc for my board. – eliba Mar 18 '14 at 10:14
  • Fix the warnings first. – alk Mar 18 '14 at 10:20
  • I have fixed all mentioned warnings, and inspected the ones that need inspection. The functions with potentially fatal warnings aren't being called during the file upload at all, so I doubt they have something to do with the problem I'm experiencing (I have inspected them as well, and it seems like there isn't any problematic code in there). The problem still persists though - I guess it's time for valgrind. Now I need to find a non-stripped version of glibc for my platform to get it to work... – eliba Mar 24 '14 at 15:11