From 70c432afd807b0b787b73271305ecb232995fccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8B=9B=E7=89=8C=E7=96=AF=E5=AD=90?= Date: Tue, 6 May 2014 17:23:28 +0800 Subject: [PATCH] [bug fixed]buaazp: sprintf error in some platform. issue #12 & #17. --- src/zhttpd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/zhttpd.c b/src/zhttpd.c index 4adc4a6..625808d 100644 --- a/src/zhttpd.c +++ b/src/zhttpd.c @@ -289,7 +289,7 @@ void post_request_cb(evhtp_request_t *req, void *arg) LOG_PRINT(LOG_DEBUG, "boundary Find. boundary = %s", boundary); - /* 依靠evbuffer自己实现php处理函数 */ + // my own muti-part/form parse evbuf_t *buf; buf = req->buffer_in; buff = (char *)malloc(post_size); @@ -326,14 +326,15 @@ void post_request_cb(evhtp_request_t *req, void *arg) const char *typePattern = "Content-Type"; const char *quotePattern = "\""; const char *blankPattern = "\r\n"; - boundaryPattern = (char *)malloc(boundary_len + 2); + LOG_PRINT(LOG_DEBUG, "boundary = %s boundary_len = %d", boundary, boundary_len); + boundaryPattern = (char *)malloc(boundary_len + 3); if(boundaryPattern == NULL) { LOG_PRINT(LOG_DEBUG, "boundarypattern malloc failed!"); goto err; } //sprintf(boundaryPattern, "\r\n--%s", boundary); - sprintf(boundaryPattern, "--%s", boundary); + snprintf(boundaryPattern, boundary_len + 3, "--%s", boundary); LOG_PRINT(LOG_DEBUG, "boundaryPattern = %s, strlen = %d", boundaryPattern, (int)strlen(boundaryPattern)); if((start = kmp(buff, post_size, fileNamePattern, strlen(fileNamePattern))) == -1) {