Make sure stdlib.h is always included before dmalloc.h to avoid problems
[oweals/busybox.git] / networking / httpd.c
index e5ad7f65e99d5aa5aa19a5482c641baa364608f6..9b36101d799cabb71567d6cad4b46a2a6f3ab629 100644 (file)
@@ -1148,10 +1148,12 @@ static int sendCgi(const char *url,
        addEnv("HTTP", "COOKIE", cookie);
       if(content_type)
        addEnv("CONTENT", "TYPE", content_type);
+#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
       if(config->remoteuser) {
        addEnv("REMOTE", "USER", config->remoteuser);
        addEnv("AUTH_TYPE", "", "Basic");
       }
+#endif
       if(config->referer)
        addEnv("HTTP", "REFERER", config->referer);
 
@@ -1269,7 +1271,9 @@ static int sendCgi(const char *url,
            }
            firstLine = 0;
          }
-         bb_full_write(s, rbuf, count);
+         if (bb_full_write(s, rbuf, count) != count)
+             break;
+
 #ifdef DEBUG
          if (config->debugHttpd)
                fprintf(stderr, "cgi read %d bytes\n", count);
@@ -1337,7 +1341,8 @@ static int sendFile(const char *url)
 
        sendHeaders(HTTP_OK);
        while ((count = bb_full_read(f, buf, MAX_MEMORY_BUFF)) > 0) {
-               bb_full_write(a_c_w, buf, count);
+               if (bb_full_write(a_c_w, buf, count) != count)
+                       break;
        }
        close(f);
   } else {
@@ -1452,7 +1457,9 @@ static int checkPerm(const char *path, const char *request)
                }
 #endif
                if (strcmp(p, request) == 0) {
+#ifdef CONFIG_FEATURE_HTTPD_AUTH_MD5
 set_remoteuser_var:
+#endif
                    config->remoteuser = strdup(request);
                    if(config->remoteuser)
                        config->remoteuser[(u - request)] = 0;
@@ -1704,8 +1711,10 @@ FORBIDDEN:      /* protect listing /cgi-bin */
 # ifdef CONFIG_FEATURE_HTTPD_CGI
   free(cookie);
   free(content_type);
-  free(config->remoteuser);
   free(config->referer);
+#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
+  free(config->remoteuser);
+#endif
 # endif
   shutdown(a_c_w, SHUT_WR);
   shutdown(a_c_r, SHUT_RD);