mg_url_encode() 0-terminate the destination

This commit is contained in:
cpq committed 2023-01-16 15:05:04 +00:00
1 parent 197be75677
commit 82d702fedc
2 files changed
+6 -6

No files matched your search

+3 -3
View File
@@ -1509,9 +1509,7 @@ int mg_url_decode(const char *src, size_t src_len, char *dst, size_t dst_len,
return i >= src_len && j < dst_len ? (int) j : -1; return i >= src_len && j < dst_len ? (int) j : -1;
} }
static bool isok(uint8_t c) { static bool isok(uint8_t c) { return c == '\n' || c == '\r' || c >= ' '; }
return c == '\n' || c == '\r' || c >= ' ';
}
int mg_http_get_request_len(const unsigned char *buf, size_t buf_len) { int mg_http_get_request_len(const unsigned char *buf, size_t buf_len) {
size_t i; size_t i;
@@ -2114,6 +2112,8 @@ size_t mg_url_encode(const char *s, size_t sl, char *buf, size_t len) {
n += 2; n += 2;
} }
} }
if (len > 0 && n < len - 1) buf[n] = '\0'; // Null-terminate the destination
if (len > 0) buf[len - 1] = '\0'; // Always.
return n; return n;
} }
+3 -3
View File
@@ -149,9 +149,7 @@ int mg_url_decode(const char *src, size_t src_len, char *dst, size_t dst_len,
return i >= src_len && j < dst_len ? (int) j : -1; return i >= src_len && j < dst_len ? (int) j : -1;
} }
static bool isok(uint8_t c) { static bool isok(uint8_t c) { return c == '\n' || c == '\r' || c >= ' '; }
return c == '\n' || c == '\r' || c >= ' ';
}
int mg_http_get_request_len(const unsigned char *buf, size_t buf_len) { int mg_http_get_request_len(const unsigned char *buf, size_t buf_len) {
size_t i; size_t i;
@@ -754,6 +752,8 @@ size_t mg_url_encode(const char *s, size_t sl, char *buf, size_t len) {
n += 2; n += 2;
} }
} }
if (len > 0 && n < len - 1) buf[n] = '\0'; // Null-terminate the destination
if (len > 0) buf[len - 1] = '\0'; // Always.
return n; return n;
} }