diff options
| author | jvoisin | 2017-09-25 20:17:33 +0200 |
|---|---|---|
| committer | jvoisin | 2017-09-25 20:17:33 +0200 |
| commit | 324b0991d2c4544635483bc9386e2e6c58d86859 (patch) | |
| tree | 01842a16120a63ea7b6d161e700b93b1aa96b60f /src | |
| parent | 1110e7e611fed787b047bf37a22b9302874f01af (diff) | |
Fix minor coverity issues
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp_utils.c | 17 | ||||
| -rw-r--r-- | src/tests/dump_request_invalid_folder.phpt | 1 |
2 files changed, 13 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 | ||
| 55 | static void construct_filename(char* filename, const char* folder) { | 55 | static 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 | ||
| 81 | int sp_log_request(const char* folder) { | 86 | int 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; |
diff --git a/src/tests/dump_request_invalid_folder.phpt b/src/tests/dump_request_invalid_folder.phpt index b866f70..e7ed45d 100644 --- a/src/tests/dump_request_invalid_folder.phpt +++ b/src/tests/dump_request_invalid_folder.phpt | |||
| @@ -21,5 +21,6 @@ echo "2\n"; | |||
| 21 | --EXPECTF-- | 21 | --EXPECTF-- |
| 22 | 1 | 22 | 1 |
| 23 | [snuffleupagus][0.0.0.0][disabled_function][drop] The call to the function 'system' in %atests/dump_request_invalid_folder.php:3 has been disabled. | 23 | [snuffleupagus][0.0.0.0][disabled_function][drop] The call to the function 'system' in %atests/dump_request_invalid_folder.php:3 has been disabled. |
| 24 | [snuffleupagus][0.0.0.0][request_logging][error] Unable to create the folder '/root/NON_EXISTENT/FOLDER/PLEASE/'. | ||
| 24 | [snuffleupagus][0.0.0.0][request_logging][error] Unable to open /root/NON_EXISTENT/FOLDER/PLEASE/sp_dump_%a_0.0.0.0.dump | 25 | [snuffleupagus][0.0.0.0][request_logging][error] Unable to open /root/NON_EXISTENT/FOLDER/PLEASE/sp_dump_%a_0.0.0.0.dump |
| 25 | 2 \ No newline at end of file | 26 | 2 \ No newline at end of file |
