fix: neu_url_decode return value on buffer overflow

This commit is contained in:
eeff
2023-06-14 15:47:19 +08:00
parent 614b949354
commit b9945c458e
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ ssize_t neu_url_decode(const char *s, size_t len, char *buf, size_t size)
}
buf[j++] = c;
}
buf[(j < size) ? j : --j] = '\0';
buf[(j < size) ? j : j - 1] = '\0';
return j;
}
+5
View File
@@ -113,6 +113,11 @@ TEST(HTTPTest, http_get_param_str)
EXPECT_EQ(ret, 3);
EXPECT_EQ(0, strcmp("组", buf));
nng_http_req_set_uri(req, "/?group=%E7%BB%84");
ret = neu_http_get_param_str(aio, "group", buf, 3);
EXPECT_EQ(ret, 3);
EXPECT_EQ(0, strncmp("组", buf, 2));
nng_aio_free(aio);
nng_http_req_free(req);
nng_url_free(url);