This is an automated email from the ASF dual-hosted git repository.
kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 407efa1 coverity fix for buffer_upload plugin
407efa1 is described below
commit 407efa1f34cef8f1434521f882ecf068ea8de930
Author: Kit Chan <[email protected]>
AuthorDate: Mon Jun 5 16:42:00 2017 -0700
coverity fix for buffer_upload plugin
---
.../experimental/buffer_upload/buffer_upload.cc | 54 ++++++++++++----------
1 file changed, 30 insertions(+), 24 deletions(-)
diff --git a/plugins/experimental/buffer_upload/buffer_upload.cc
b/plugins/experimental/buffer_upload/buffer_upload.cc
index c2c4c37..6ca2981 100644
--- a/plugins/experimental/buffer_upload/buffer_upload.cc
+++ b/plugins/experimental/buffer_upload/buffer_upload.cc
@@ -278,9 +278,8 @@ pvc_process_accept(TSCont contp, int event, void *edata,
pvc_state *my_state)
my_state->resp_buffer = TSIOBufferCreate();
my_state->resp_reader = TSIOBufferReaderAlloc(my_state->resp_buffer);
- if ((my_state->req_buffer == nullptr) || (my_state->req_reader == nullptr)
|| (my_state->resp_buffer == nullptr) ||
- (my_state->resp_reader == nullptr)) {
- LOG_ERROR("TSIOBufferCreate || TSIOBufferReaderAlloc");
+ if ((my_state->req_reader == nullptr) || (my_state->resp_reader ==
nullptr)) {
+ LOG_ERROR("TSIOBufferReaderAlloc");
TSVConnClose(my_state->p_vc);
pvc_cleanup(contp, my_state);
} else {
@@ -598,7 +597,10 @@ convert_url_func(TSMBuffer req_bufp, TSMLoc req_loc)
return;
}
- char *hostname = (char *)getenv("HOSTNAME");
+ const char *hostname = getenv("HOSTNAME");
+ if (hostname == nullptr) {
+ return;
+ }
// in reverse proxy mode, TSUrlHostGet returns NULL here
str = TSUrlHostGet(req_bufp, url_loc, &len);
@@ -936,17 +938,17 @@ create_directory()
struct dirent *d;
if (getcwd(cwd, 4096) == nullptr) {
- TSError("[buffer_upload] getcwd fails");
+ TSError("[%s] getcwd fails", PLUGIN_NAME);
return 0;
}
if (chdir(uconfig->base_dir) < 0) {
if (mkdir(uconfig->base_dir, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
- TSError("[buffer_upload] Unable to enter or create %s",
uconfig->base_dir);
+ TSError("[%s] Unable to enter or create %s", PLUGIN_NAME,
uconfig->base_dir);
goto error_out;
}
if (chdir(uconfig->base_dir) < 0) {
- TSError("[buffer_upload] Unable enter %s", uconfig->base_dir);
+ TSError("[%s] Unable enter %s", PLUGIN_NAME, uconfig->base_dir);
goto error_out;
}
}
@@ -954,11 +956,11 @@ create_directory()
snprintf(str, 10, "%02X", i);
if (chdir(str) < 0) {
if (mkdir(str, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
- TSError("[buffer_upload] Unable to enter or create %s/%s",
uconfig->base_dir, str);
+ TSError("[%s] Unable to enter or create %s/%s", PLUGIN_NAME,
uconfig->base_dir, str);
goto error_out;
}
if (chdir(str) < 0) {
- TSError("[buffer_upload] Unable to enter %s/%s", uconfig->base_dir,
str);
+ TSError("[%s] Unable to enter %s/%s", PLUGIN_NAME, uconfig->base_dir,
str);
goto error_out;
}
}
@@ -967,7 +969,10 @@ create_directory()
goto error_out;
}
while ((d = readdir(dir))) {
- remove(d->d_name);
+ if (remove(d->d_name) < 0) {
+ TSError("[%s] Unable to remove '%s': %s", PLUGIN_NAME, d->d_name,
strerror(errno));
+ goto error_out;
+ }
}
closedir(dir);
if (chdir("..") == -1) {
@@ -1007,7 +1012,7 @@ load_urls(char *filename)
for (i = 0; i < 2; i++) {
if ((file = TSfopen(filename, "r")) == nullptr) {
TSfree(url_buf);
- TSError("[buffer_upload] Fail to open %s", filename);
+ TSError("[%s] Fail to open %s", PLUGIN_NAME, filename);
return;
}
if (i == 0) { // first round
@@ -1055,7 +1060,7 @@ parse_config_line(char *line, const struct config_val_ul
*cv)
int iv = strtol(tok, &end, 10);
if (end && *end == '\0') {
*((int *)cv->val) = iv;
- TSError("[buffer_upload] Parsed int config value %s : %d",
cv->str, iv);
+ TSError("[%s] Parsed int config value %s : %d", PLUGIN_NAME,
cv->str, iv);
TSDebug(DEBUG_TAG, "Parsed int config value %s : %d", cv->str, iv);
}
break;
@@ -1065,7 +1070,7 @@ parse_config_line(char *line, const struct config_val_ul
*cv)
unsigned int uiv = strtoul(tok, &end, 10);
if (end && *end == '\0') {
*((unsigned int *)cv->val) = uiv;
- TSError("[buffer_upload] Parsed uint config value %s : %u",
cv->str, uiv);
+ TSError("[%s] Parsed uint config value %s : %u", PLUGIN_NAME,
cv->str, uiv);
TSDebug(DEBUG_TAG, "Parsed uint config value %s : %u", cv->str,
uiv);
}
break;
@@ -1075,7 +1080,7 @@ parse_config_line(char *line, const struct config_val_ul
*cv)
long lv = strtol(tok, &end, 10);
if (end && *end == '\0') {
*((long *)cv->val) = lv;
- TSError("[buffer_upload] Parsed long config value %s : %ld",
cv->str, lv);
+ TSError("[%s] Parsed long config value %s : %ld", PLUGIN_NAME,
cv->str, lv);
TSDebug(DEBUG_TAG, "Parsed long config value %s : %ld", cv->str,
lv);
}
break;
@@ -1085,7 +1090,7 @@ parse_config_line(char *line, const struct config_val_ul
*cv)
unsigned long ulv = strtoul(tok, &end, 10);
if (end && *end == '\0') {
*((unsigned long *)cv->val) = ulv;
- TSError("[buffer_upload] Parsed ulong config value %s : %lu",
cv->str, ulv);
+ TSError("[%s] Parsed ulong config value %s : %lu", PLUGIN_NAME,
cv->str, ulv);
TSDebug(DEBUG_TAG, "Parsed ulong config value %s : %lu", cv->str,
ulv);
}
break;
@@ -1095,7 +1100,7 @@ parse_config_line(char *line, const struct config_val_ul
*cv)
if (len > 0) {
*((char **)cv->val) = (char *)TSmalloc(len + 1);
strcpy(*((char **)cv->val), tok);
- TSError("[buffer_upload] Parsed string config value %s : %s",
cv->str, tok);
+ TSError("[%s] Parsed string config value %s : %s", PLUGIN_NAME,
cv->str, tok);
TSDebug(DEBUG_TAG, "Parsed string config value %s : %s", cv->str,
tok);
}
break;
@@ -1108,7 +1113,7 @@ parse_config_line(char *line, const struct config_val_ul
*cv)
} else {
*((bool *)cv->val) = false;
}
- TSError("[buffer_upload] Parsed bool config value %s : %d",
cv->str, *((bool *)cv->val));
+ TSError("[%s] Parsed bool config value %s : %d", PLUGIN_NAME,
cv->str, *((bool *)cv->val));
TSDebug(DEBUG_TAG, "Parsed bool config value %s : %d", cv->str,
*((bool *)cv->val));
}
break;
@@ -1162,7 +1167,7 @@ read_upload_config(const char *file_name)
}
TSfclose(conf_file);
} else {
- TSError("[buffer_upload] Failed to open upload config file %s", file_name);
+ TSError("[%s] Failed to open upload config file %s", PLUGIN_NAME,
file_name);
// if fail to open config file, use the default config
}
@@ -1205,15 +1210,16 @@ TSPluginInit(int argc, const char *argv[])
if (!read_upload_config(conf_filename) || !uconfig) {
if (argc > 1) {
- TSError("[buffer_upload] Failed to read upload config %s", argv[1]);
+ TSError("[%s] Failed to read upload config %s", PLUGIN_NAME, argv[1]);
} else {
- TSError("[buffer_upload] No config file specified. Specify conf file in
plugin.conf: "
- "'buffer_upload.so /path/to/upload.conf'");
+ TSError("[%s] No config file specified. Specify conf file in
plugin.conf: "
+ "'buffer_upload.so /path/to/upload.conf'",
+ PLUGIN_NAME);
}
}
// set the num of threads for disk AIO
if (TSAIOThreadNumSet(uconfig->thread_num) == TS_ERROR) {
- TSError("[buffer_upload] Failed to set thread number");
+ TSError("[%s] Failed to set thread number", PLUGIN_NAME);
}
TSDebug(DEBUG_TAG, "uconfig->url_list_file: %s", uconfig->url_list_file);
@@ -1227,12 +1233,12 @@ TSPluginInit(int argc, const char *argv[])
info.support_email = const_cast<char *>("[email protected]");
if (uconfig->use_disk_buffer && !create_directory()) {
- TSError("[buffer_upload] Directory creation failed");
+ TSError("[%s] Directory creation failed", PLUGIN_NAME);
uconfig->use_disk_buffer = false;
}
if (TSPluginRegister(&info) != TS_SUCCESS) {
- TSError("[buffer_upload] Plugin registration failed");
+ TSError("[%s] Plugin registration failed", PLUGIN_NAME);
}
/* create the statistic variables */
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].