...
Code Block | ||
---|---|---|
| ||
/* ... */
char *new_secret;
size_t size = strlen(secret);
if (size == SIZE_MAX) {
/* Handle Error */
}
new_secret = (char *)malloc(size+1);
if (!new_secret) {
/* Handle Error */
}
strcpy(new_secret, secret);
/* Process new_secret... */
free(new_secret);
/* ... */
|
...
Code Block | ||
---|---|---|
| ||
/* ... */
char *new_secret;
size_t size = strlen(secret);
if (size == SIZE_MAX) {
/* Handle Error */
}
/* use calloc() to zero-out allocated space */
new_secret = (char *)calloc(size+1, sizeof(char));
if (!new_secret) {
/* Handle Error */
}
strcpy(new_secret, secret);
/* Process new_secret... */
/* sanitize memory */
memset(new_secret, '\0', size);
free(new_secret);
/* ... */
|
...
Code Block | ||
---|---|---|
| ||
/* ... */
size_t secret_size;
/* ... */
if (secret_size > SIZE_MAX/2) {
/* handle error condition */
}
secret = (char *)realloc(secret, secret_size * 2);
/* ... */
|
...
Code Block | ||
---|---|---|
| ||
/* ... */
size_t secret_size;
/* ... */
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;
/* ... */
|
...