fprintf(stderr, "Failed to execute mget: %s\n",
memcached_strerror(memc, rc));
memcached_quit(memc);
- return EXIT_SUCCESS;
+ return 0;
}
}
else
fprintf(stderr, "Failed to execute mget: %s\n",
memcached_strerror(memc, rc));
memcached_quit(memc);
- return EXIT_SUCCESS;
+ return 0;
}
return retrieved;
sasl_secret_t **psecret)
{
(void)context;
- static sasl_secret_t* x;
+ static sasl_secret_t* ptr;
if (!conn || ! psecret || id != SASL_CB_PASS)
return SASL_BADPARAM;
}
size_t len= strlen(passwd);
- x = realloc(x, sizeof(sasl_secret_t) + len);
- if (!x)
+ ptr= malloc(sizeof(sasl_secret_t) + len +1);
+ if (! ptr)
return SASL_NOMEM;
- x->len = len;
- strcpy((void *)x->data, passwd);
+ ptr->len= len;
+ memcpy(ptr->data, passwd, len);
+ ptr->data[len]= 0;
- *psecret = x;
+ *psecret= ptr;
return SASL_OK;
}
else
perror("getaddrinfo()");
- return EXIT_FAILURE;
+ return 0;
}
struct linger ling= {0, 0};
#ifdef HAVE_HSIEH_HASH
return libhashkit_hsieh(key, key_length);
#else
- return EXIT_FAILURE;
+ return 1;
#endif
case HASHKIT_HASH_MURMUR:
#ifdef HAVE_MURMUR_HASH
return libhashkit_murmur(key, key_length);
#else
- return EXIT_FAILURE;
+ return 1;
#endif
case HASHKIT_HASH_JENKINS:
return libhashkit_jenkins(key, key_length);
break;
}
- return EXIT_FAILURE;
+ return 1;
}
int rem;
if (key_length <= 0 || key == NULL)
- return EXIT_SUCCESS;
+ return 0;
rem = key_length & 3;
key_length >>= 2;
hashkit_continuum_point_st *ct2= (hashkit_continuum_point_st *)t2;
if (ct1->value == ct2->value)
- return EXIT_SUCCESS;
+ return 0;
else if (ct1->value > ct2->value)
- return EXIT_FAILURE;
+ return 1;
else
return -1;
}
live_servers= (uint32_t)hashkit->list_size;
if (live_servers == 0)
- return EXIT_SUCCESS;
+ return 0;
if (hashkit->weight_fn == NULL)
{
qsort(hashkit->continuum, hashkit->continuum_points_count, sizeof(hashkit_continuum_point_st),
continuum_points_cmp);
- return EXIT_SUCCESS;
+ return 0;
}
#endif
memset(&servAddr, 0, sizeof (struct sockaddr_un));
servAddr.sun_family= AF_UNIX;
- strcpy(servAddr.sun_path, ptr->hostname); /* Copy filename */
+ strncpy(servAddr.sun_path, ptr->hostname, sizeof(servAddr.sun_path)); /* Copy filename */
test_connect:
if (connect(ptr->fd,
WATCHPOINT_ASSERT(memcached_server_count(ptr));
if (memcached_server_count(ptr) == 1)
- return EXIT_SUCCESS;
+ return 0;
if (ptr->flags.hash_with_prefix_key)
{
char temp[temp_length];
if (temp_length > MEMCACHED_MAX_KEY -1)
- return EXIT_SUCCESS;
+ return 0;
strncpy(temp, memcached_array_string(ptr->prefix_key), memcached_array_size(ptr->prefix_key));
strncpy(temp + memcached_array_size(ptr->prefix_key), key, key_length);
/* Why 153? Hmmm... */
WATCHPOINT_ASSERT(ct1->value != 153);
if (ct1->value == ct2->value)
- return EXIT_SUCCESS;
+ return 0;
else if (ct1->value > ct2->value)
- return EXIT_FAILURE;
+ return 1;
else
return -1;
}
and protocol enforcement happens at memcached_response()
looking for '\n'. We do not care for UDB which requests 8 bytes
at once. Generally, this means that connection went away. Since
- for blocking I/O we do not return EXIT_SUCCESS and for non-blocking case
+ for blocking I/O we do not return 0 and for non-blocking case
it will return EGAIN if data is not immediatly available.
*/
WATCHPOINT_STRING("We had a zero length recv()");
if (ptr->write_buffer_offset == 0 || (ptr->type == MEMCACHED_CONNECTION_UDP
&& ptr->write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH))
- return EXIT_SUCCESS;
+ return 0;
/* Looking for memory overflows */
#if defined(DEBUG)
if (len == 0 || len > 240 || (*c != '\0' && *c != '\r' && iscntrl(*c)))
{
- return EXIT_SUCCESS;
+ return 0;
}
return len;
{
/* Keep on reading */
recover_tokenize_command(start, *end);
- return EXIT_FAILURE;
+ return 1;
}
void *data= (*end) + 1;
*end += nbytes + 2;
- return EXIT_SUCCESS;
+ return 0;
}
static int process_cas_command(memcached_protocol_client_st *client,
void memcached_quit_server(memcached_server_st *ptr, bool io_death)
{
- if (ptr->fd != -1)
+ if (ptr->fd != INVALID_SOCKET)
{
if (io_death == false && ptr->type != MEMCACHED_CONNECTION_UDP && ptr->options.is_shutting_down == false)
{
}
else
{
- rc= memcached_do(ptr, "quit\r\n", strlen("quit\r\n"), true);
+ rc= memcached_do(ptr, "quit\r\n", sizeof("quit\r\n") -1, true);
}
WATCHPOINT_ASSERT(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_FETCH_NOTFINISHED);
memcached_io_close(ptr);
}
- ptr->fd= -1;
+ ptr->fd= INVALID_SOCKET;
ptr->io_bytes_sent= 0;
ptr->write_buffer_offset= (size_t) ((ptr->type == MEMCACHED_CONNECTION_UDP) ? UDP_DATAGRAM_HEADER_LENGTH : 0);
ptr->read_buffer_length= 0;
void memcached_quit(memcached_st *ptr)
{
- uint32_t x;
-
- if (memcached_server_count(ptr) == 0)
- return;
-
if (memcached_server_count(ptr))
{
- for (x= 0; x < memcached_server_count(ptr); x++)
+ for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
memcached_server_write_instance_st instance=
memcached_server_instance_fetch(ptr, x);
sasl_callback_t *cb= libmemcached_calloc(ptr, 4, sizeof(sasl_callback_t));
char *name= libmemcached_malloc(ptr, strlen(username) + 1);
- sasl_secret_t *secret= libmemcached_malloc(ptr, strlen(password) + 1 + sizeof(*secret))
-;
+ size_t password_length= strlen(password);
+ sasl_secret_t *secret= libmemcached_malloc(ptr, password_length +1 + sizeof(*secret));
if (cb == NULL || name == NULL || secret == NULL)
{
libmemcached_free(ptr, cb);
}
secret->len= strlen(password);
- strcpy((void*)secret->data, password);
+ memcpy(secret->data, password, password_length);
+ secret->data[password_length]= 0;
cb[0].id= SASL_CB_USER;
cb[0].proc= get_username;
- cb[0].context= strcpy(name, username);
+ cb[0].context= strncpy(name, username, sizeof(cb[0].context));
cb[1].id= SASL_CB_AUTHNAME;
cb[1].proc= get_username;
cb[1].context= name;
libmemcached_free(clone, cb);
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
}
- strcpy(cb[x].context, source->sasl.callbacks[x].context);
+ strncpy(cb[x].context, source->sasl.callbacks[x].context, sizeof(cb[x].context));
}
else
{
if (hostname == NULL || error == NULL)
return NULL;
- if (! port)
+ if (hostname[0] == '/')
+ port = 0;
+ else if (! port)
port= MEMCACHED_DEFAULT_PORT;
/* Increment count for hosts */
}
/* @todo Check return type */
- memcached_server_create_with(NULL, &new_host_list[count-1], hostname, port, weight, MEMCACHED_CONNECTION_TCP);
+ memcached_server_create_with(NULL, &new_host_list[count-1], hostname, port, weight, port ? MEMCACHED_CONNECTION_TCP : MEMCACHED_CONNECTION_UNIX_SOCKET);
// Handset allocated since
new_host_list->options.is_allocated= true;
*error= MEMCACHED_SUCCESS;
- if (!memcmp("pid", key, strlen("pid")))
+ if (!memcmp("pid", key, sizeof("pid") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->pid);
- else if (!memcmp("uptime", key, strlen("uptime")))
+ else if (!memcmp("uptime", key, sizeof("uptime") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->uptime);
- else if (!memcmp("time", key, strlen("time")))
+ else if (!memcmp("time", key, sizeof("time") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->time);
- else if (!memcmp("version", key, strlen("version")))
+ else if (!memcmp("version", key, sizeof("version") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%s", memc_stat->version);
- else if (!memcmp("pointer_size", key, strlen("pointer_size")))
+ else if (!memcmp("pointer_size", key, sizeof("pointer_size") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->pointer_size);
- else if (!memcmp("rusage_user", key, strlen("rusage_user")))
+ else if (!memcmp("rusage_user", key, sizeof("rusage_user") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%u.%u", memc_stat->rusage_user_seconds, memc_stat->rusage_user_microseconds);
- else if (!memcmp("rusage_system", key, strlen("rusage_system")))
+ else if (!memcmp("rusage_system", key, sizeof("rusage_system") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%u.%u", memc_stat->rusage_system_seconds, memc_stat->rusage_system_microseconds);
- else if (!memcmp("curr_items", key, strlen("curr_items")))
+ else if (!memcmp("curr_items", key, sizeof("curr_items") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->curr_items);
- else if (!memcmp("total_items", key, strlen("total_items")))
+ else if (!memcmp("total_items", key, sizeof("total_items") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->total_items);
- else if (!memcmp("curr_connections", key, strlen("curr_connections")))
+ else if (!memcmp("curr_connections", key, sizeof("curr_connections") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->curr_connections);
- else if (!memcmp("total_connections", key, strlen("total_connections")))
+ else if (!memcmp("total_connections", key, sizeof("total_connections") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->total_connections);
- else if (!memcmp("connection_structures", key, strlen("connection_structures")))
+ else if (!memcmp("connection_structures", key, sizeof("connection_structures") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->connection_structures);
- else if (!memcmp("cmd_get", key, strlen("cmd_get")))
+ else if (!memcmp("cmd_get", key, sizeof("cmd_get") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->cmd_get);
- else if (!memcmp("cmd_set", key, strlen("cmd_set")))
+ else if (!memcmp("cmd_set", key, sizeof("cmd_set") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->cmd_set);
- else if (!memcmp("get_hits", key, strlen("get_hits")))
+ else if (!memcmp("get_hits", key, sizeof("get_hits") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->get_hits);
- else if (!memcmp("get_misses", key, strlen("get_misses")))
+ else if (!memcmp("get_misses", key, sizeof("get_misses") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->get_misses);
- else if (!memcmp("evictions", key, strlen("evictions")))
+ else if (!memcmp("evictions", key, sizeof("evictions") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->evictions);
- else if (!memcmp("bytes_read", key, strlen("bytes_read")))
+ else if (!memcmp("bytes_read", key, sizeof("bytes_read") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes_read);
- else if (!memcmp("bytes_written", key, strlen("bytes_written")))
+ else if (!memcmp("bytes_written", key, sizeof("bytes_written") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes_written);
- else if (!memcmp("bytes", key, strlen("bytes")))
+ else if (!memcmp("bytes", key, sizeof("bytes") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes);
- else if (!memcmp("limit_maxbytes", key, strlen("limit_maxbytes")))
+ else if (!memcmp("limit_maxbytes", key, sizeof("limit_maxbytes") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->limit_maxbytes);
- else if (!memcmp("threads", key, strlen("threads")))
+ else if (! memcmp("threads", key, sizeof("threads") -1))
length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->threads);
else
{
char *response_ptr;
const char *command= "version\r\n";
- send_length= strlen(command);
+ send_length= sizeof("version\r\n") -1;
rc= MEMCACHED_SUCCESS;
for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
static test_return_t memcached_server_cursor_test(memcached_st *memc)
{
- char context[8];
- strcpy(context, "foo bad");
+ char context[10];
+ strncpy(context, "foo bad", sizeof(context));
memcached_server_fn callbacks[1];
callbacks[0]= server_function;
/* Test a long key for failure */
/* TODO, extend test to determine based on setting, what result should be */
- strcpy(long_key, "Thisismorethentheallottednumberofcharacters");
+ strncpy(long_key, "Thisismorethentheallottednumberofcharacters", sizeof(long_key));
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, long_key);
//test_true(rc == MEMCACHED_BAD_KEY_PROVIDED);
test_true(rc == MEMCACHED_SUCCESS);
/* Now test a key with spaces (which will fail from long key, since bad key is not set) */
- strcpy(long_key, "This is more then the allotted number of characters");
+ strncpy(long_key, "This is more then the allotted number of characters", sizeof(long_key));
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, long_key);
test_true(rc == MEMCACHED_BAD_KEY_PROVIDED);
rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_VERIFY_KEY, 1);
test_true(rc == MEMCACHED_SUCCESS);
- strcpy(long_key, "dog cat");
+ strncpy(long_key, "dog cat", sizeof(long_key));
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, long_key);
test_true(rc == MEMCACHED_BAD_KEY_PROVIDED);
}
/* put failure limit to 1 */
rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, 1);
assert(rc == MEMCACHED_SUCCESS);
+
/* Put a retry timeout to effectively activate failure_limit effect */
rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 1);
assert(rc == MEMCACHED_SUCCESS);
+
/* change behavior that triggers memcached_quit()*/
rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1);
assert(rc == MEMCACHED_SUCCESS);