From 653158eabbef431378ac54e7a512e9d549c85b56 Mon Sep 17 00:00:00 2001 From: "F. Duncanh" Date: Mon, 17 Apr 2023 18:51:34 -0400 Subject: [PATCH] fix errors in recent sprintf->snprintf "fix" --- lib/http_request.c | 2 +- lib/utils.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/http_request.c b/lib/http_request.c index 2a1936e..e259a60 100644 --- a/lib/http_request.c +++ b/lib/http_request.c @@ -276,7 +276,7 @@ http_request_get_header_string(http_request_t *request, char **header_str) assert(str); *header_str = str; char *p = str; - int n = sizeof(str); + int n = len + 1; for (int i = 0; i < request->headers_size; i++) { int hlen = strlen(request->headers[i]); snprintf(p, n, "%s", request->headers[i]); diff --git a/lib/utils.c b/lib/utils.c index 9ba21f5..07788ec 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -191,7 +191,7 @@ char *utils_data_to_string(const unsigned char *data, int datalen, int chars_per char *str = (char *) calloc(len + 1, sizeof(char)); assert(str); char *p = str; - int n = sizeof(str); + int n = len + 1; for (int i = 0; i < datalen; i++) { if (i > 0 && i % chars_per_line == 0) { snprintf(p, n, "\n");