]> xenbits.xensource.com Git - xen.git/commit
libelf: use C99 bool for booleans
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 14 Jun 2013 15:39:36 +0000 (16:39 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 14 Jun 2013 15:39:36 +0000 (16:39 +0100)
commit7a549a6aa04dba807f8dd4c1577ab6a7592c4c76
tree6958cff3e5eb8b755805f327cfc8d56052af2efa
parentc84481fbc7de7d15ff7476b3b9cd2713f81feaa3
libelf: use C99 bool for booleans

We want to remove uses of "int" because signed integers have
undesirable undefined behaviours on overflow.  Malicious compilers can
turn apparently-correct code into code with security vulnerabilities
etc.

In this patch we change all the booleans in libelf to C99 bool,
from <stdbool.h>.

For the one visible libelf boolean in libxc's public interface we
retain the use of int to avoid changing the ABI; libxc converts it to
a bool for consumption by libelf.

It is OK to change all values only ever used as booleans to _Bool
(bool) because conversion from any scalar type to a _Bool works the
same as the boolean test in if() or ?: and is always defined (C99
6.3.1.2).  But we do need to check that all these variables really are
only ever used that way.  (It is theoretically possible that the old
code truncated some 64-bit values to 32-bit ints which might become
zero depending on the value, which would mean a behavioural change in
this patch, but it seems implausible that treating 0x????????00000000
as false could have been intended.)

This is part of the fix to a security issue, XSA-55.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
v3: Use <stdbool.h>'s bool (or _Bool) instead of defining elf_bool.
    Split this into a separate patch.
tools/libxc/xc_dom_elfloader.c
xen/common/libelf/libelf-dominfo.c
xen/common/libelf/libelf-loader.c
xen/common/libelf/libelf-private.h
xen/common/libelf/libelf-tools.c
xen/include/xen/libelf.h