Commit 0c990eb0 authored by Milan Broz's avatar Milan Broz

Merge branch 'stoeckmann/cryptsetup-malloc'

parents ea5e9c9f 23ce9aa4
......@@ -57,8 +57,8 @@ struct volume_key {
char key[];
};
struct volume_key *crypt_alloc_volume_key(unsigned keylength, const char *key);
struct volume_key *crypt_generate_volume_key(struct crypt_device *cd, unsigned keylength);
struct volume_key *crypt_alloc_volume_key(size_t keylength, const char *key);
struct volume_key *crypt_generate_volume_key(struct crypt_device *cd, size_t keylength);
void crypt_free_volume_key(struct volume_key *vk);
/* Device backend */
......
......@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
......@@ -97,7 +98,7 @@ void *crypt_safe_alloc(size_t size)
{
struct safe_allocation *alloc;
if (!size)
if (!size || size > (SIZE_MAX - offsetof(struct safe_allocation, data)))
return NULL;
alloc = malloc(size + offsetof(struct safe_allocation, data));
......
......@@ -20,14 +20,19 @@
*/
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include "internal.h"
struct volume_key *crypt_alloc_volume_key(unsigned keylength, const char *key)
struct volume_key *crypt_alloc_volume_key(size_t keylength, const char *key)
{
struct volume_key *vk = malloc(sizeof(*vk) + keylength);
struct volume_key *vk;
if (!keylength || keylength > (SIZE_MAX - sizeof(*vk)))
return NULL;
vk = malloc(sizeof(*vk) + keylength);
if (!vk)
return NULL;
......@@ -49,7 +54,7 @@ void crypt_free_volume_key(struct volume_key *vk)
}
}
struct volume_key *crypt_generate_volume_key(struct crypt_device *cd, unsigned keylength)
struct volume_key *crypt_generate_volume_key(struct crypt_device *cd, size_t keylength)
{
int r;
struct volume_key *vk;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment