From e32b4a9a81ee7bd5698b2522b886e151d1c40a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 5 Aug 2022 17:40:26 +0200 Subject: [PATCH] Declare read-only parameters const Signal callers arguments are not going to be modified and allow passing const pointers. --- lib/prototypes.h | 2 +- libmisc/find_new_gid.c | 2 +- libmisc/find_new_uid.c | 2 +- libmisc/getrange.c | 2 +- libmisc/idmapping.c | 8 ++++---- libmisc/idmapping.h | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/prototypes.h b/lib/prototypes.h index cd873bf7..4e997e32 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -159,7 +159,7 @@ extern int getlong (const char *numstr, /*@out@*/long int *result); extern int get_pid (const char *pidstr, pid_t *pid); /* getrange */ -extern int getrange (char *range, +extern int getrange (const char *range, unsigned long *min, bool *has_min, unsigned long *max, bool *has_max); diff --git a/libmisc/find_new_gid.c b/libmisc/find_new_gid.c index 1bddc12f..666b6107 100644 --- a/libmisc/find_new_gid.c +++ b/libmisc/find_new_gid.c @@ -98,7 +98,7 @@ static int get_ranges (bool sys_group, gid_t *min_id, gid_t *max_id, static int check_gid (const gid_t gid, const gid_t gid_min, const gid_t gid_max, - bool *used_gids) + const bool *used_gids) { /* First test that the preferred ID is in the range */ if (gid < gid_min || gid > gid_max) { diff --git a/libmisc/find_new_uid.c b/libmisc/find_new_uid.c index 41b6c1d1..322d15ab 100644 --- a/libmisc/find_new_uid.c +++ b/libmisc/find_new_uid.c @@ -98,7 +98,7 @@ static int get_ranges (bool sys_user, uid_t *min_id, uid_t *max_id, static int check_uid(const uid_t uid, const uid_t uid_min, const uid_t uid_max, - bool *used_uids) + const bool *used_uids) { /* First test that the preferred ID is in the range */ if (uid < uid_min || uid > uid_max) { diff --git a/libmisc/getrange.c b/libmisc/getrange.c index d620c126..82f2edfa 100644 --- a/libmisc/getrange.c +++ b/libmisc/getrange.c @@ -25,7 +25,7 @@ * If the range is valid, getrange returns 1. * If the range is not valid, getrange returns 0. */ -int getrange (char *range, +int getrange (const char *range, unsigned long *min, bool *has_min, unsigned long *max, bool *has_max) { diff --git a/libmisc/idmapping.c b/libmisc/idmapping.c index 8b64a26a..30eb89fd 100644 --- a/libmisc/idmapping.c +++ b/libmisc/idmapping.c @@ -102,10 +102,10 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv) #define ULONG_DIGITS ((((sizeof(unsigned long) * CHAR_BIT) + 9)/10)*3) #if HAVE_SYS_CAPABILITY_H -static inline bool maps_lower_root(int cap, int ranges, struct map_range *mappings) +static inline bool maps_lower_root(int cap, int ranges, const struct map_range *mappings) { int idx; - struct map_range *mapping; + const struct map_range *mapping; if (cap != CAP_SETUID) return false; @@ -135,11 +135,11 @@ static inline bool maps_lower_root(int cap, int ranges, struct map_range *mappin * when the root user calls the new{g,u}idmap binary for an unprivileged user. * If this is wanted: use file capabilities! */ -void write_mapping(int proc_dir_fd, int ranges, struct map_range *mappings, +void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings, const char *map_file, uid_t ruid) { int idx; - struct map_range *mapping; + const struct map_range *mapping; size_t bufsize; char *buf, *pos; int fd; diff --git a/libmisc/idmapping.h b/libmisc/idmapping.h index 81a628b8..e20bd60f 100644 --- a/libmisc/idmapping.h +++ b/libmisc/idmapping.h @@ -15,7 +15,7 @@ struct map_range { extern struct map_range *get_map_ranges(int ranges, int argc, char **argv); extern void write_mapping(int proc_dir_fd, int ranges, - struct map_range *mappings, const char *map_file, uid_t ruid); + const struct map_range *mappings, const char *map_file, uid_t ruid); #endif /* _ID_MAPPING_H_ */