Author: igalic
Date: Mon Sep 19 14:52:40 2011
New Revision: 1172649
URL: http://svn.apache.org/viewvc?rev=1172649&view=rev
Log:
TS-953: consolidate string copy/concat for the rest of proxy/.
Modified:
trafficserver/traffic/trunk/proxy/FetchSM.cc
trafficserver/traffic/trunk/proxy/ICP.cc
trafficserver/traffic/trunk/proxy/ICPConfig.cc
trafficserver/traffic/trunk/proxy/ParentSelection.cc
trafficserver/traffic/trunk/proxy/Prefetch.cc
trafficserver/traffic/trunk/proxy/StatPages.cc
trafficserver/traffic/trunk/proxy/StatSystem.cc
trafficserver/traffic/trunk/proxy/Update.cc
trafficserver/traffic/trunk/proxy/logstats.cc
trafficserver/traffic/trunk/proxy/sac.cc
Modified: trafficserver/traffic/trunk/proxy/FetchSM.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/FetchSM.cc?rev=1172649&r1=1172648&r2=1172649&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/FetchSM.cc (original)
+++ trafficserver/traffic/trunk/proxy/FetchSM.cc Mon Sep 19 14:52:40 2011
@@ -99,7 +99,7 @@ FetchSM::get_info_from_buffer(IOBufferRe
info = (char *)ats_malloc(sizeof(char) * (read_avail+1));
client_response = info;
- //strncpy(info, _headers.data(), hdr_size);
+ //ink_strlcpy(info, _headers.data(), sizeof(char) * (read_avail+1));
//info += hdr_size;
/* Read the data out of the reader */
Modified: trafficserver/traffic/trunk/proxy/ICP.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ICP.cc?rev=1172649&r1=1172648&r2=1172649&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ICP.cc (original)
+++ trafficserver/traffic/trunk/proxy/ICP.cc Mon Sep 19 14:52:40 2011
@@ -2021,7 +2021,7 @@ ICPProcessor::BuildPeerList()
// parents and siblings.
//
Pcfg = _ICPConfig->indexToPeerConfigData(0);
- ink_strncpy(Pcfg->_hostname, "localhost", sizeof(Pcfg->_hostname));
+ ink_strlcpy(Pcfg->_hostname, "localhost", sizeof(Pcfg->_hostname));
Pcfg->_ctype = PeerConfigData::CTYPE_LOCAL;
// Get IP address for given interface
Modified: trafficserver/traffic/trunk/proxy/ICPConfig.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ICPConfig.cc?rev=1172649&r1=1172648&r2=1172649&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ICPConfig.cc (original)
+++ trafficserver/traffic/trunk/proxy/ICPConfig.cc Mon Sep 19 14:52:40 2011
@@ -543,9 +543,9 @@ ICPConfiguration::icp_config_change_call
ink_assert(filename);
char ConfigFilePath[PATH_NAME_MAX];
if (filename) {
- ink_strncpy(ConfigFilePath, system_config_directory,
sizeof(ConfigFilePath));
- strncat(ConfigFilePath, "/", sizeof(ConfigFilePath) -
strlen(ConfigFilePath) - 1);
- strncat(ConfigFilePath, filename, sizeof(ConfigFilePath) -
strlen(ConfigFilePath) - 1);
+ ink_strlcpy(ConfigFilePath, system_config_directory,
sizeof(ConfigFilePath));
+ ink_strlcat(ConfigFilePath, "/", sizeof(ConfigFilePath));
+ ink_strlcat(ConfigFilePath, filename, sizeof(ConfigFilePath));
}
int fd = open(ConfigFilePath, O_RDONLY);
if (fd < 0) {
@@ -622,8 +622,7 @@ ICPConfiguration::icp_config_change_call
next = strchr(cur, ':');
*next++ = 0;
if (cur != (next - 1)) {
- strncpy(P[n]._hostname, cur, PeerConfigData::HOSTNAME_SIZE);
- P[n]._hostname[PeerConfigData::HOSTNAME_SIZE - 1] = 0;
+ ink_strlcpy(P[n]._hostname, cur, PeerConfigData::HOSTNAME_SIZE);
} else {
P[n]._hostname[0] = 0;
}
Modified: trafficserver/traffic/trunk/proxy/ParentSelection.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ParentSelection.cc?rev=1172649&r1=1172648&r2=1172649&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ParentSelection.cc (original)
+++ trafficserver/traffic/trunk/proxy/ParentSelection.cc Mon Sep 19 14:52:40
2011
@@ -1,6 +1,6 @@
/** @file
- A brief file description
+ Implementation of Parent Proxy routing
@section license License
@@ -21,11 +21,6 @@
limitations under the License.
*/
-/*****************************************************************************
- *
- * ParentSelection.cc - Implementation of Parent Proxy routing
- *
- ****************************************************************************/
#include "ink_unused.h" /* MAGIC_EDITING_TAG */
@@ -1084,7 +1079,7 @@ EXCLUSIVE_REGRESSION_TEST(PARENTSELECTIO
config.startup();
params->ParentEnable = true;
char tbl[2048];
-#define T(x) strncat(tbl,x, sizeof(tbl));
+#define T(x) ink_strlcat(tbl,x, sizeof(tbl));
#define REBUILD params->ParentTable = new P_table("", "ParentSelection Unit
Test Table", &http_dest_tags, ALLOW_HOST_TABLE | ALLOW_REGEX_TABLE |
ALLOW_IP_TABLE | DONT_BUILD_TABLE);
params->ParentTable->BuildTableFromString(tbl);
HttpRequestData *request = NULL;
ParentResult *result = NULL;
@@ -1291,12 +1286,9 @@ verify(ParentResult * r, ParentResultTyp
void
br(HttpRequestData * h, const char *os_hostname, int dest_ip)
{
- int hostname_len = strlen(os_hostname) + 1;
-
h->hdr = new HTTPHdr();
h->hdr->create(HTTP_TYPE_REQUEST);
- h->hostname_str = (char *)ats_malloc(hostname_len);
- ink_strncpy(h->hostname_str, os_hostname, hostname_len);
+ h->hostname_str = (char *)ats_strdup(os_hostname);
h->xact_start = time(NULL);
h->src_ip = 0;
h->dest_ip = dest_ip;
Modified: trafficserver/traffic/trunk/proxy/Prefetch.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/Prefetch.cc?rev=1172649&r1=1172648&r2=1172649&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/Prefetch.cc (original)
+++ trafficserver/traffic/trunk/proxy/Prefetch.cc Mon Sep 19 14:52:40 2011
@@ -483,9 +483,8 @@ PrefetchTransform::redirect(HTTPHdr *res
int redirect_url_len = 0;
const char *tmp_url = resp->value_get(MIME_FIELD_LOCATION,
MIME_LEN_LOCATION, &redirect_url_len);
- redirect_url = (char *)ats_malloc(redirect_url_len + 1);
- strncpy(redirect_url, tmp_url, redirect_url_len);
- redirect_url[redirect_url_len] = '\0';
+ redirect_url = (char *)alloca(redirect_url_len + 1);
+ ink_strlcpy(redirect_url, tmp_url, redirect_url_len + 1);
Debug("PrefetchTransform", "redirect_url = %s\n", redirect_url);
} else {
response_status = -1;
@@ -507,7 +506,6 @@ PrefetchTransform::redirect(HTTPHdr *res
Debug("PrefetchTransform", "Redirect url to HTTP Hdr Location:
\'%s\'\n", redirect_url);
if (strncmp(redirect_url, req_url, location_len) == 0) {
Debug("PrefetchTransform", "'%s' -> '%s' - Could be a loop.
Discontinuing this path.\n", req_url, redirect_url);
- ats_free(redirect_url);
ats_free(req_url);
return 0;
}
@@ -516,7 +514,6 @@ PrefetchTransform::redirect(HTTPHdr *res
if (!entry) {
Debug("PrefetchParserURLs", "Ignoring duplicate url '%s'",
redirect_url);
- ats_free(redirect_url);
ats_free(req_url);
return 0;
}
@@ -529,7 +526,6 @@ PrefetchTransform::redirect(HTTPHdr *res
ats_free(req_url);
}
}
- ats_free(redirect_url);
return 0;
}
@@ -993,18 +989,16 @@ PrefetchBlaster::init(PrefetchUrlEntry *
p_trans->domain_start, p_trans->domain_end,
p_trans->host_start, p_trans->host_len,
p_trans->no_dot_in_host);
+ // FIXME? ip_len is pretty useless here.
int ip_len;
const char *ip_str;
if (IS_RECURSIVE_PREFETCH(entry->req_ip) &&
(ip_str = request->value_get(MIME_FIELD_CLIENT_IP, MIME_LEN_CLIENT_IP,
&ip_len))) {
//this is a recursive prefetch. get child ip address from
//Client-IP header
- if (ip_len > 15)
- ip_len = 15;
char ip_buf[16];
- strncpy(ip_buf, ip_str, ip_len);
- ip_buf[ip_len] = '\0';
+ ink_strlcpy(ip_buf, ip_str, sizeof(ip_buf));
entry->child_ip = inet_addr(ip_buf);
} else
Modified: trafficserver/traffic/trunk/proxy/StatPages.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/StatPages.cc?rev=1172649&r1=1172648&r2=1172649&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/StatPages.cc (original)
+++ trafficserver/traffic/trunk/proxy/StatPages.cc Mon Sep 19 14:52:40 2011
@@ -78,7 +78,7 @@ StatPagesManager::handle_http(Continuati
int i;
h = url->host_get(&host_len);
- ink_strncpy(host, h, host_len >= 1023 ? 1024 : host_len + 1);
+ ink_strlcpy(host, h, sizeof(host));
host_len = unescapifyStr(host);
for (i = 0; i < n_stat_pages; i++) {
@@ -101,7 +101,7 @@ bool StatPagesManager::is_stat_page(URL
if (h == NULL || length < 2)
return false;
- ink_strncpy(host, h, length >= 1023 ? 1024 : length + 1);
+ ink_strlcpy(host, h, sizeof(host));
length = unescapifyStr(host);
if ((host[0] == '{') && (host[length - 1] == '}'))
@@ -119,8 +119,7 @@ bool StatPagesManager::is_cache_inspecto
if (h == NULL || length < 2)
return false;
- ink_strncpy(host, h, length >= 1023 ? 1024 : length + 1);
- host[length] = '\0';
+ ink_strlcpy(host, h, sizeof(host));
length = unescapifyStr(host);
if (strncmp(host, "{cache}", length) == 0)
Modified: trafficserver/traffic/trunk/proxy/StatSystem.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/StatSystem.cc?rev=1172649&r1=1172648&r2=1172649&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/StatSystem.cc (original)
+++ trafficserver/traffic/trunk/proxy/StatSystem.cc Mon Sep 19 14:52:40 2011
@@ -411,13 +411,12 @@ stat_callback(Continuation * cont, HTTPH
int buffer_len = 0;
int num_prefix_buffer;
- char *var_prefix = (char *)ats_malloc((length + 1) * sizeof(char));
+ char *var_prefix = (char *)alloca((length + 1) * sizeof(char));
memset(var_prefix, 0, ((length + 1) * sizeof(char)));
- strncpy(var_prefix, path, length);
+ ink_strlcpy(var_prefix, path, length + 1);
num_prefix_buffer = RecGetRecordPrefix_Xmalloc(var_prefix, &buffer,
&buffer_len);
empty = (num_prefix_buffer == 0);
- ats_free(var_prefix);
if (!empty) {
@@ -432,7 +431,7 @@ stat_callback(Continuation * cont, HTTPH
if (!empty) {
StatPageData data;
- strncat(result, "</pre>\n", result_size - strlen(result) - 1);
+ ink_strlcat(result, "</pre>\n", result_size);
data.data = result;
data.length = strlen(result);
Modified: trafficserver/traffic/trunk/proxy/Update.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/Update.cc?rev=1172649&r1=1172648&r2=1172649&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/Update.cc (original)
+++ trafficserver/traffic/trunk/proxy/Update.cc Mon Sep 19 14:52:40 2011
@@ -886,9 +886,9 @@ UpdateConfigManager::BuildUpdateList()
char ConfigFilePath[PATH_NAME_MAX];
if (_filename) {
- ink_strncpy(ConfigFilePath, system_config_directory,
sizeof(ConfigFilePath));
- strncat(ConfigFilePath, "/", sizeof(ConfigFilePath) -
strlen(ConfigFilePath) - 1);
- strncat(ConfigFilePath, _filename, sizeof(ConfigFilePath) -
strlen(ConfigFilePath) - 1);
+ ink_strlcpy(ConfigFilePath, system_config_directory,
sizeof(ConfigFilePath));
+ ink_strlcat(ConfigFilePath, "/", sizeof(ConfigFilePath));
+ ink_strlcat(ConfigFilePath, _filename, sizeof(ConfigFilePath));
} else {
return (UpdateConfigList *) NULL;
}
Modified: trafficserver/traffic/trunk/proxy/logstats.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logstats.cc?rev=1172649&r1=1172648&r2=1172649&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logstats.cc (original)
+++ trafficserver/traffic/trunk/proxy/logstats.cc Mon Sep 19 14:52:40 2011
@@ -651,7 +651,8 @@ static const char *USAGE_LINE =
"Usage: " PROGRAM_NAME " [-f logfile] [-o origin[,...]] [-O originfile] [-m
minhits] [-inshv]";
void
-CommandLineArgs::parse_arguments(char** argv) {
+CommandLineArgs::parse_arguments(char** argv)
+{
// process command-line arguments
process_args(argument_descriptions, n_argument_descriptions, argv,
USAGE_LINE);
@@ -666,7 +667,7 @@ CommandLineArgs::parse_arguments(char**
char buffer[MAX_ORIG_STRING];
char *tok, *sep_ptr, *val;
- ink_strlcpy(buffer, query, MAX_ORIG_STRING);
+ ink_strlcpy(buffer, query, sizeof(buffer));
unescapifyStr(buffer);
for (tok = strtok_r(buffer, "&", &sep_ptr); tok != NULL;) {
@@ -674,7 +675,7 @@ CommandLineArgs::parse_arguments(char**
if (val)
*(val++) = '\0';
if (0 == strncmp(tok, "origin_list", 11)) {
- ink_strlcpy(origin_list, val, MAX_ORIG_STRING);
+ ink_strlcpy(origin_list, val, sizeof(origin_list));
} else if (0 == strncmp(tok, "state_tag", 9)) {
ink_strlcpy(state_tag, val, sizeof(state_tag));
} else if (0 == strncmp(tok, "max_origins", 11)) {
@@ -736,11 +737,11 @@ struct ExitStatus
if (l > level)
level = l;
if (n)
- strncat(notice, n, sizeof(notice) - strlen(notice) - 1);
+ ink_strlcat(notice, n, sizeof(notice));
}
void append(const char *n) {
- strncat(notice, n, sizeof(notice) - strlen(notice) - 1);
+ ink_strlcat(notice, n, sizeof(notice));
}
};
@@ -2230,7 +2231,7 @@ main(int argc, char *argv[])
parse_errors = 0;
// Get log directory
- ink_strlcpy(system_log_dir, Layout::get()->logdir, PATH_NAME_MAX);
+ ink_strlcpy(system_log_dir, Layout::get()->logdir, sizeof(system_log_dir));
if (-1 == access(system_log_dir, R_OK)) {
fprintf(stderr, "unable to change to log directory \"%s\" [%d '%s']\n",
system_log_dir, errno, strerror(errno));
fprintf(stderr, " please set correct path in env variable TS_ROOT \n");
Modified: trafficserver/traffic/trunk/proxy/sac.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/sac.cc?rev=1172649&r1=1172648&r2=1172649&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/sac.cc (original)
+++ trafficserver/traffic/trunk/proxy/sac.cc Mon Sep 19 14:52:40 2011
@@ -1,6 +1,6 @@
/** @file
- A brief file description
+ Standalone Collator
@section license License
@@ -21,13 +21,6 @@
limitations under the License.
*/
-/***************************************************************************
- sac.cc
-
- Standalone Collator
-
-
- ***************************************************************************/
#include "ink_config.h"
#include "ink_file.h"
#include "ink_unused.h"
@@ -101,7 +94,7 @@ main(int argc, char *argv[])
process_args(argument_descriptions, n_argument_descriptions, argv);
// Get log directory
- ink_strlcpy(system_log_dir, Layout::get()->logdir, PATH_NAME_MAX);
+ ink_strlcpy(system_log_dir, Layout::get()->logdir, sizeof(system_log_dir));
if (access(system_log_dir, R_OK) == -1) {
fprintf(stderr, "unable to change to log directory \"%s\" [%d '%s']\n",
system_log_dir, errno, strerror(errno));
fprintf(stderr, " please set correct path in env variable TS_ROOT \n");
@@ -109,7 +102,7 @@ main(int argc, char *argv[])
}
management_directory[0] = 0;
- strncat(management_directory, system_config_directory, 256 - 1);
+ ink_strlcat(management_directory, system_config_directory,
sizeof(management_directory));
// check for the version number request
//