瀏覽代碼

Added sanity checking in send_file_data()

Sergey Lyubka 12 年之前
父節點
當前提交
94e1c5a41b
共有 1 個文件被更改,包括 3 次插入0 次删除
  1. 3 0
      mongoose.c

+ 3 - 0
mongoose.c

@@ -2727,6 +2727,9 @@ static void send_file_data(struct mg_connection *conn, struct file *filep,
   char buf[MG_BUF_LEN];
   int to_read, num_read, num_written;
 
+  // Sanity check the offset
+  offset = offset < 0 ? 0 : offset > filep->size ? filep->size : offset;
+
   if (len > 0 && filep->membuf != NULL && filep->size > 0) {
     if (len > filep->size - offset) {
       len = filep->size - offset;