mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-18 10:59:45 +00:00
mg_url_encode() 0-terminate the destination
This commit is contained in:
1 parent
197be75677
commit
82d702fedc
2 files changed
+10
-10
No files matched your search
+5
-5
@@ -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;
|
||||
}
|
||||
|
||||
static bool isok(uint8_t c) {
|
||||
return c == '\n' || c == '\r' || c >= ' ';
|
||||
}
|
||||
static bool isok(uint8_t c) { return c == '\n' || c == '\r' || c >= ' '; }
|
||||
|
||||
int mg_http_get_request_len(const unsigned char *buf, size_t buf_len) {
|
||||
size_t i;
|
||||
@@ -356,7 +354,7 @@ static void static_cb(struct mg_connection *c, int ev, void *ev_data,
|
||||
// Read to send IO buffer directly, avoid extra on-stack buffer
|
||||
size_t n, max = MG_IO_SIZE, space;
|
||||
size_t *cl = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) /
|
||||
sizeof(size_t) * sizeof(size_t)];
|
||||
sizeof(size_t) * sizeof(size_t)];
|
||||
if (c->send.size < max) mg_iobuf_resize(&c->send, max);
|
||||
if (c->send.len >= c->send.size) return; // Rate limit
|
||||
if ((space = c->send.size - c->send.len) > *cl) space = *cl;
|
||||
@@ -529,7 +527,7 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm,
|
||||
} else {
|
||||
// Track to-be-sent content length at the end of c->data, aligned
|
||||
size_t *clp = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) /
|
||||
sizeof(size_t) * sizeof(size_t)];
|
||||
sizeof(size_t) * sizeof(size_t)];
|
||||
c->pfn = static_cb;
|
||||
c->pfn_data = fd;
|
||||
*clp = (size_t) cl;
|
||||
@@ -754,6 +752,8 @@ size_t mg_url_encode(const char *s, size_t sl, char *buf, size_t len) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user