Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a bunch of problems with this code. It's hard to say why it's crashing on these files considering the number of potential problems (you did not provide a sample input that crashes your program)</p> <ul> <li><p>For this problem to be usable you need to set SO_REUSEADDR on the socket, otherwise if it is crashes (hint, hint), you will not be able to restart it right away and receive connections</p></li> <li><p>you do not check the return value of bind(), accept(), pthread_create()</p></li> <li><p>you need to call listen() only once, not in the loop</p></li> <li><p>it's safer to cast fd to long before to cast it to void * since that's what you do in listen. A cleaner way would involve a struct on the heap with an fd in it </p></li> <li><p>Do not define the size of arrays that you set at compile time, let the compiler do it. It's safer: <code>char header[]="HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";</code>. Then you do not need to call strlen on it. You can just use <code>sizeof(header) - 1</code>.</p></li> <li><p>You do not check the return value of recv(). You must make sure it did not fail (esp since you use it as an index in an array)</p></li> <li><p>You do not ensure that filename is not overflowed. You read up to 65K, yet you do not make sure that filename is big enough (i.e it's trivial to crash your program and it's a security vulnerability)</p></li> <li><p>You do not read the return value of sscanf. There is no guarantee that filename has data</p></li> <li><p>You are not nul terminating filename_parsed (I believe it's the main reason your program is crashing)</p></li> <li><p>You might to call strlen(filename_parsed) only once and instead of calling it a zillion times</p></li> <li><p>Instead of your confusing character checks at the end, why not use strcmp (once filename_parsed is properly terminate of course): <code>0 == strcmp(filename_parsed + len - 5, ".jpeg")</code> etc.</p></li> <li>Check the return value of send</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload