Skip to content

Commit

Permalink
libelf: avoid UB in elf_xen_feature_{get,set}()
Browse files Browse the repository at this point in the history
When the left shift amount is up to 31, the shifted quantity wants to be
of unsigned int (or wider) type.

While there also adjust types: get doesn't alter the array and returns a
boolean, while both don't really accept negative "nr". Drop a stray
blank each as well.

Signed-off-by: Jan Beulich <[email protected]>
Reviewed-by: Andrew Cooper <[email protected]>
Release-Acked-By: Oleksii Kurochko <[email protected]>
  • Loading branch information
jbeulich authored and andyhhp committed Jun 21, 2024
1 parent c5746b0 commit 9e7c26a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions xen/include/xen/libelf.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,13 @@ struct elf_dom_parms {
uint64_t virt_kend;
};

static inline void elf_xen_feature_set(int nr, uint32_t * addr)
static inline void elf_xen_feature_set(unsigned int nr, uint32_t *addr)
{
addr[nr >> 5] |= 1 << (nr & 31);
addr[nr >> 5] |= 1U << (nr & 31);
}
static inline int elf_xen_feature_get(int nr, uint32_t * addr)
static inline bool elf_xen_feature_get(unsigned int nr, const uint32_t *addr)
{
return !!(addr[nr >> 5] & (1 << (nr & 31)));
return addr[nr >> 5] & (1U << (nr & 31));
}

elf_errorstatus elf_xen_parse_features(const char *features,
Expand Down

0 comments on commit 9e7c26a

Please sign in to comment.