Skip to content

Commit

Permalink
libselinux: limit has buffer size
Browse files Browse the repository at this point in the history
The `struct selabel_digest` member `hashbuf_size` is used to compute
hashes via `Sha1Update()`, which takes uint32_t as length parameter
type.  Use that same type for `hashbuf_size` to avoid potential value
truncations, as the overflow check in `digest_add_specfile()` on
`hashbuf_size` is based on it.

    label_support.c: In function ‘digest_gen_hash’:
    label_support.c:125:53: warning: conversion from ‘size_t’ {aka ‘long unsigned int’} to ‘uint32_t’ {aka ‘unsigned int’} may change value [-Wconversion]
      125 |         Sha1Update(&context, digest->hashbuf, digest->hashbuf_size);
          |                                               ~~~~~~^~~~~~~~~~~~~~

Acked-by: James Carter <jwcart2@gmail.com>
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
  • Loading branch information
cgzones authored and jwcart2 committed Apr 12, 2022
1 parent 9d57ab6 commit 0aa974a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion libselinux/src/label_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int selabel_service_init(struct selabel_handle *rec,
struct selabel_digest {
unsigned char *digest; /* SHA1 digest of specfiles */
unsigned char *hashbuf; /* buffer to hold specfiles */
size_t hashbuf_size; /* buffer size */
uint32_t hashbuf_size; /* buffer size */
size_t specfile_cnt; /* how many specfiles processed */
char **specfile_list; /* and their names */
};
Expand Down

0 comments on commit 0aa974a

Please sign in to comment.