Created
April 6, 2012 21:04
-
-
Save mnunberg/2322914 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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