aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremias Stotter <jeremias@stotter.eu>2021-11-21 19:18:43 +0100
committerJeremias Stotter <jeremias@stotter.eu>2021-11-21 19:18:43 +0100
commitb25fb6ba2e8f884f2b4c4d7b58ca5876e7eefc65 (patch)
tree0a950e27903d7bd17c02a47296db45d1df4e5d4d
parentea2efb515ba2c27619a4ec729d427b737d8adbc0 (diff)
downloadJBlog-b25fb6ba2e8f884f2b4c4d7b58ca5876e7eefc65.tar.gz
JBlog-b25fb6ba2e8f884f2b4c4d7b58ca5876e7eefc65.tar.bz2
JBlog-b25fb6ba2e8f884f2b4c4d7b58ca5876e7eefc65.zip
Changed some malloc to calloc
This seems to fixes a few bugs Somewhere a few terminating 0 bytes go missing, this is the lazy way to fix that (:
-rw-r--r--admin.c3
-rw-r--r--jblog.c14
2 files changed, 8 insertions, 9 deletions
diff --git a/admin.c b/admin.c
index e8e9ed9..0bd50e7 100644
--- a/admin.c
+++ b/admin.c
@@ -409,7 +409,6 @@ int post_admin(char* buffer, size_t buffer_size, char* req_content, size_t req_c
char publish_path[PATH_MAX] = "";
snprintf(publish_path, PATH_MAX, "%s/%s", base_path, publish_to);
int publish_file = open(publish_path, O_CREAT | O_RDWR, 0600);
- printf("%s\n", publish_path);
if(publish_file < 0) {
snprintf(buffer, buffer_size, "<p><b>Error publishing \"%s\": %s</b></p>", publish_to, strerror(errno));
return 1;
@@ -420,7 +419,7 @@ int post_admin(char* buffer, size_t buffer_size, char* req_content, size_t req_c
return 1;
}
- snprintf(buffer, buffer_size, "<p><b>Published successfully to <a href=\"%s/!\">%s</a> (Click to refresh cache)</b></p>", publish_to, publish_to);
+ snprintf(buffer, buffer_size, "<p><b>Published successfully to <a target=\"_blank\" href=\"%s/!\">%s</a> (Click to refresh cache)</b></p>", publish_to, publish_to);
close(publish_file);
return 1;
}
diff --git a/jblog.c b/jblog.c
index e6cbe27..e8c94f4 100644
--- a/jblog.c
+++ b/jblog.c
@@ -340,9 +340,9 @@ int handle_request(int socket) {
fprintf(stderr, "Error: Upload too big\n");
return -1;
}
- content = malloc(content_length + 1);
+ content = calloc(content_length + 1, 1);
if(content == NULL) {
- perror("malloc error");
+ perror("calloc error");
return -1;
}
size_t read_bytes = 0;
@@ -462,9 +462,9 @@ int read_jblog_file(char* buffer, int buffer_size, char* file_name, int* error_c
*error_code = 403;
return 0;
}
- char* blog_content = malloc(jblog_stat.st_size);
+ char* blog_content = calloc(jblog_stat.st_size, 1);
if(blog_content == NULL) {
- perror("malloc error");
+ perror("calloc error");
*error_code = 500;
return 0;
}
@@ -490,9 +490,9 @@ int read_jblog_file(char* buffer, int buffer_size, char* file_name, int* error_c
}
bool wrap_html = true;
- char* html = malloc(buffer_size);
+ char* html = calloc(buffer_size, 1);
if(html == NULL) {
- perror("malloc error");
+ perror("calloc error");
free(blog_content);
*error_code = 500;
return 0;
@@ -600,7 +600,7 @@ int create_html(char* content, size_t content_length, char request_uri[1024], ch
strcpy(*buffer, HTML_ERROR(405));
return 405;
}
- *buffer = malloc(MAX_REPLY);
+ *buffer = calloc(MAX_REPLY, 1);
if(buffer == NULL) {
perror("malloc error");
return -1;
Jeremias Stotters git repositories generated by CGIT