Skip to content

Instantly share code, notes, and snippets.

@mnunberg
Created April 6, 2012 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnunberg/2322914 to your computer and use it in GitHub Desktop.
Save mnunberg/2322914 to your computer and use it in GitHub Desktop.
/**
* Some versions of glibc do not take kindly to copying
* into a char[1] even if it's within valid address space
*/
#define LIBCOUCHBASE_SASL_MAXPWLEN(instance) \
((sizeof(instance->sasl.password.buffer) - \
sizeof(instance->sasl.secret.len))-1)
void
libcouchbase_set_sasl_password(libcouchbase_t instance, const char *passwd)
{
size_t pwlen = strlen(passwd);
if (pwlen > LIBCOUCHBASE_SASL_MAXPWLEN(instance)) {
fprintf(stderr, "Possible buffer overflow - password too long!\n");
abort();
}
instance->password.secret.len = pwlen;
memcpy(intance->password.buffer +
(sizeof (instance->password.buffer) -
LIBCOUCHBASE_SASL_MAXPWLEN(instance)),
passwd,
pwlen);
}
/*
* ....
*/
if (passwd) {
libcouchbase_sat_sasl_password(instance, passwd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment