summaryrefslogtreecommitdiff
path: root/src/sp_utils.c
diff options
context:
space:
mode:
authorjvoisin2017-09-25 20:17:33 +0200
committerjvoisin2017-09-25 20:17:33 +0200
commit324b0991d2c4544635483bc9386e2e6c58d86859 (patch)
tree01842a16120a63ea7b6d161e700b93b1aa96b60f /src/sp_utils.c
parent1110e7e611fed787b047bf37a22b9302874f01af (diff)
Fix minor coverity issues
Diffstat (limited to 'src/sp_utils.c')
-rw-r--r--src/sp_utils.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/sp_utils.c b/src/sp_utils.c
index 2370a6d..f696a55 100644
--- a/src/sp_utils.c
+++ b/src/sp_utils.c
@@ -52,14 +52,17 @@ int compute_hash(const char* const filename, char* file_hash) {
52 return SUCCESS; 52 return SUCCESS;
53} 53}
54 54
55static void construct_filename(char* filename, const char* folder) { 55static int construct_filename(char* filename, const char* folder) {
56 time_t t = time(NULL); 56 time_t t = time(NULL);
57 struct tm* tm = localtime(&t); // FIXME use `localtime_r` instead 57 struct tm* tm = localtime(&t); // FIXME use `localtime_r` instead
58 struct timeval tval; 58 struct timeval tval;
59 struct stat st = {0}; 59 struct stat st = {0};
60 60
61 if (-1 == stat(folder, &st)) { 61 if (-1 == stat(folder, &st)) {
62 mkdir(folder, 0700); 62 if (0 != mkdir(folder, 0700)) {
63 sp_log_err("request_logging", "Unable to create the folder '%s'.",
64 folder);
65 }
63 } 66 }
64 67
65 memcpy(filename, folder, strlen(folder)); 68 memcpy(filename, folder, strlen(folder));
@@ -70,12 +73,14 @@ static void construct_filename(char* filename, const char* folder) {
70 strcat(filename, "_"); 73 strcat(filename, "_");
71 74
72 char* remote_addr = getenv("REMOTE_ADDR"); 75 char* remote_addr = getenv("REMOTE_ADDR");
73 if (remote_addr) { 76 if (remote_addr) { // ipv6: 8*4 bytes + 7 colons = 39 chars max
74 strcat(filename, remote_addr); 77 strncat(filename, remote_addr, 40);
75 } else { 78 } else {
76 strcat(filename, "0.0.0.0"); 79 strcat(filename, "0.0.0.0");
77 } 80 }
78 strcat(filename, ".dump"); 81 strcat(filename, ".dump");
82
83 return 0;
79} 84}
80 85
81int sp_log_request(const char* folder) { 86int sp_log_request(const char* folder) {
@@ -90,7 +95,9 @@ int sp_log_request(const char* folder) {
90 {"COOKIE", TRACK_VARS_COOKIE}, {"SERVER", TRACK_VARS_SERVER}, 95 {"COOKIE", TRACK_VARS_COOKIE}, {"SERVER", TRACK_VARS_SERVER},
91 {"ENV", TRACK_VARS_ENV}, {NULL, 0}}; 96 {"ENV", TRACK_VARS_ENV}, {NULL, 0}};
92 97
93 construct_filename(filename, folder); 98 if (0 != construct_filename(filename, folder)) {
99 return -1;
100 }
94 if (NULL == (file = fopen(filename, "a"))) { 101 if (NULL == (file = fopen(filename, "a"))) {
95 sp_log_err("request_logging", "Unable to open %s", filename); 102 sp_log_err("request_logging", "Unable to open %s", filename);
96 return -1; 103 return -1;