浏览代码

Fix possible overflow on query_string

xtne6f 6 年之前
父节点
当前提交
df1b672518
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. 3 2
      src/civetweb.c

+ 3 - 2
src/civetweb.c

@@ -9098,8 +9098,8 @@ compare_dir_entries(const void *p1, const void *p2)
 		const char *query_string = a->conn->request_info.query_string;
 		int cmp_result = 0;
 
-		if (query_string == NULL) {
-			query_string = "na";
+		if ((query_string == NULL) || (query_string[0] == '\0')) {
+			query_string = "n";
 		}
 
 		if (a->file.is_directory && !b->file.is_directory) {
@@ -9333,6 +9333,7 @@ handle_directory_request(struct mg_connection *conn, const char *dir)
 	}
 
 	sort_direction = ((conn->request_info.query_string != NULL)
+	                  && (conn->request_info.query_string[0] != '\0')
 	                  && (conn->request_info.query_string[1] == 'd'))
 	                     ? 'a'
 	                     : 'd';