diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2007-11-22 10:40:45 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2007-11-22 10:40:45 +0000 |
commit | a07275a632da9a58d2daa5ce25871e1383323b07 (patch) | |
tree | a402bcbf046c86e3e9e7e60c9bade53bc987fecf /tools/libxc/xc_core.c | |
parent | 1b50906da253729ce4f7dc010aed3e7d59d6351d (diff) | |
download | xen-a07275a632da9a58d2daa5ce25871e1383323b07.tar.gz xen-a07275a632da9a58d2daa5ce25871e1383323b07.tar.bz2 xen-a07275a632da9a58d2daa5ce25871e1383323b07.zip |
libxc: Minor clean up of xc_core, and fix for -fstrict-overflow.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Diffstat (limited to 'tools/libxc/xc_core.c')
-rw-r--r-- | tools/libxc/xc_core.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/tools/libxc/xc_core.c b/tools/libxc/xc_core.c index 021d069c1c..a4327101b6 100644 --- a/tools/libxc/xc_core.c +++ b/tools/libxc/xc_core.c @@ -107,17 +107,23 @@ xc_core_strtab_get(struct xc_core_strtab *strtab, const char *name) uint16_t ret = 0; uint16_t len = strlen(name) + 1; + if ( strtab->current > UINT16_MAX - len ) + { + PERROR("too long string table"); + errno = E2BIG; + return ret; + } + if ( strtab->current + len > strtab->max ) { char *tmp; - if ( strtab->max * 2 < strtab->max ) + if ( strtab->max > UINT16_MAX / 2 ) { PERROR("too long string table"); errno = ENOMEM; return ret; } - tmp = realloc(strtab->strings, strtab->max * 2); if ( tmp == NULL ) { @@ -143,8 +149,8 @@ struct xc_core_section_headers { Elf64_Shdr *shdrs; }; -#define SHDR_INIT 16 -#define SHDR_INC 4U +#define SHDR_INIT ((uint16_t)16) +#define SHDR_INC ((uint16_t)4) static struct xc_core_section_headers* xc_core_shdr_init(void) @@ -180,7 +186,7 @@ xc_core_shdr_get(struct xc_core_section_headers *sheaders) if ( sheaders->num == sheaders->num_max ) { Elf64_Shdr *shdrs; - if ( sheaders->num_max + SHDR_INC < sheaders->num_max ) + if ( sheaders->num_max > UINT16_MAX - SHDR_INC ) { errno = E2BIG; return NULL; |