From 84f8afe5b5cb3ddb0ade023de4c4fac9d4672e2e Mon Sep 17 00:00:00 2001 From: Leonardo Araujo Date: Fri, 19 Jul 2024 02:27:59 -0300 Subject: [PATCH] fix: use snsprintf in views --- src/views.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/views.c b/src/views.c index 99e780c..6143afb 100644 --- a/src/views.c +++ b/src/views.c @@ -13,7 +13,7 @@ void root_view(void *client_socket) content = "Hello world!"; printf("[%s] - ", current_date); printf("\033[0;32mHTTP/1.1 200 OK\033[0m\n"); - sprintf(server_message, "HTTP/1.1 200 OK\nDate: %s\nContent-Type: text/html\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); + snprintf(server_message, sizeof(server_message), "HTTP/1.1 200 OK\nDate: %s\nContent-Type: text/html\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); send(*(int *)client_socket, server_message, strlen(server_message), 0); } @@ -32,7 +32,7 @@ void get_users_view(void *client_socket) printf("[%s] - ", current_date); printf("\033[0;32mHTTP/1.1 200 OK\033[0m\n"); - sprintf(server_message, "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); + snprintf(server_message, sizeof(server_message), "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); send(*(int *)client_socket, server_message, strlen(server_message), 0); } @@ -51,7 +51,7 @@ void get_user_view(void *client_socket, unsigned int id) printf("[%s] - ", current_date); printf("\033[0;32mHTTP/1.1 200 OK\033[0m\n"); - sprintf(server_message, "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); + snprintf(server_message, sizeof(server_message), "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); send(*(int *)client_socket, server_message, strlen(server_message), 0); } @@ -70,7 +70,7 @@ void delete_user_view(void *client_socket, unsigned int id) printf("[%s] - ", current_date); printf("\033[0;32mHTTP/1.1 200 OK\033[0m\n"); - sprintf(server_message, "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); + snprintf(server_message, sizeof(server_message), "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); send(*(int *)client_socket, server_message, strlen(server_message), 0); } @@ -89,7 +89,7 @@ void update_user_view(void *client_socket, unsigned int id, char struct_string[N printf("[%s] - ", current_date); printf("\033[0;32mHTTP/1.1 200 OK\033[0m\n"); - sprintf(server_message, "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); + snprintf(server_message, sizeof(server_message), "HTTP/1.1 200 OK\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); send(*(int *)client_socket, server_message, strlen(server_message), 0); } @@ -108,7 +108,7 @@ void create_user_view(void *client_socket, char struct_string[NUM_COLS][STR_LEN] printf("[%s] - ", current_date); printf("\033[0;32mHTTP/1.1 201 Created\033[0m\n"); - sprintf(server_message, "HTTP/1.1 201 Created\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); + snprintf(server_message, sizeof(server_message), "HTTP/1.1 201 Created\nDate: %s\nContent-Type: application/json\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); send(*(int *)client_socket, server_message, strlen(server_message), 0); } @@ -124,6 +124,6 @@ void error_not_found(void *client_socket) content = "

Error 404 - not found

"; printf("[%s] - ", current_date); printf("\033[0;31mHTTP/1.1 404 Not Found\033[0m\n"); - sprintf(server_message, "HTTP/1.1 404 Not Found\nDate: %s\nContent-Type: text/html\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); + snprintf(server_message, sizeof(server_message), "HTTP/1.1 404 Not Found\nDate: %s\nContent-Type: text/html\nContent-Length: %ld\n\n%s", current_date, strlen(content), content); send(*(int *)client_socket, server_message, strlen(server_message), 0); }