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;
}
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,
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
{
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);
}