Forgot to attach the patch.

On 04/10/2013 06:00 PM, Lauri Kasanen wrote:
On Wed, 10 Apr 2013 17:54:42 +0300
Lauri Kasanen <[email protected]> wrote:

Hi

This seems quite weird, wouldn't this break if the app specifies anything else 
for content_type? What happens if CONTENT_TYPE=text/plain, much shorter?
Replying to myself; if sr->content_type is not NULL-terminated, then the 
correct solution is to include the length, see the HTTP_HOST line above for an 
example.

- Lauri

>From aa67934f352a930c2a7dcf611d6dad78da042bff Mon Sep 17 00:00:00 2001
From: Denis Mone <[email protected]>
Date: Wed, 10 Apr 2013 16:08:32 +0300
Subject: [PATCH] Follow up on bug #172. There is a problem with the sr data
 structure the sr->content_type.data field contains the
 content_type value as well as the content_length value.This
 in combination with the SHORTLEN value(64) leads wrong
 characters being copied to the content_type ENV variable.

---
 plugins/cgi/cgi.c |    3 ++-
 plugins/cgi/cgi.h |    2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/plugins/cgi/cgi.c b/plugins/cgi/cgi.c
index 48afba9..79f65c1 100644
--- a/plugins/cgi/cgi.c
+++ b/plugins/cgi/cgi.c
@@ -25,6 +25,7 @@
 
 #include "cgi.h"
 
+
 MONKEY_PLUGIN("cgi",		/* shortname */
               "CGI handler",	/* name */
               VERSION,		/* version */
@@ -170,7 +171,7 @@ static int do_cgi(const char *const __restrict__ file,
     }
 
     if (sr->content_type.len) {
-        snprintf(content_type, SHORTLEN, "CONTENT_TYPE=%s", sr->content_type.data);
+        snprintf(content_type, SHORTLEN, "CONTENT_TYPE=%.*s", (int)sr->content_type.len, sr->content_type.data);
         env[envpos++] = content_type;
     }
 
diff --git a/plugins/cgi/cgi.h b/plugins/cgi/cgi.h
index f9d89c7..1e41b56 100644
--- a/plugins/cgi/cgi.h
+++ b/plugins/cgi/cgi.h
@@ -35,7 +35,7 @@
 
 enum {
     PATHLEN = 1024,
-    SHORTLEN = 64;
+    SHORTLEN = 64
 };
 
 struct cgi_request {
-- 
1.7.10.4

_______________________________________________
Monkey mailing list
[email protected]
http://lists.monkey-project.com/listinfo/monkey

Reply via email to