...
Code Block | ||
---|---|---|
| ||
char *secret;
/* initialize secret */
size_t secret_size = strlen(secret);
/* ... */
if (secret_size > SIZE_MAX/2) {
/* handle error condition */
}
secret = (char *)realloc(secret, secret_size * 2);
|
...
Code Block | ||
---|---|---|
| ||
char *secret;
/* initialize secret */
size_t secret_size = strlen(secret);
/* ... */
if (secret_size > SIZE_MAX/2) {
/* handle error condition */
}
/* calloc() initializes memory to zero */
temp_buff = (char *)calloc(secret_size * 2, sizeof(char));
if (temp_buff == NULL) {
/* Handle Error */
}
memcpy(temp_buff, secret, secret_size);
/* sanitize the buffer */
memset(secret, '\0', secret_size);
free(secret);
secret = temp_buff; /* install the resized buffer */
temp_buff = NULL;
|
...