From dbe68128a079ee6869dc42aee37bf403e137218b Mon Sep 17 00:00:00 2001 From: Christian Göttsche Date: Mon, 7 Aug 2023 14:31:30 +0200 Subject: pam_env: remove allocator sizeof operator mismatch An array of strings is allocated (into a pointer) so the single array element to be allocated is char*. Since sizeof(char**) should be always equal to sizeof(char*) this caused no issues so far. Reported by Clang analyzer: pam_env.c:391:14: warning: Result of 'malloc' is converted to a pointer of type 'char *', which is incompatible with sizeof operand type 'char **' [unix.MallocSizeof] 391 | *lines = malloc((i + 1)* sizeof(char**)); | ^~~~~~ ~~~~~~~~~~~~~~ pam_env.c:401:13: warning: Result of 'realloc' is converted to a pointer of type 'char *', which is incompatible with sizeof operand type 'char **' [unix.MallocSizeof] 401 | tmp = realloc(*lines, (++i + 1) * sizeof(char**)); | ^~~~~~~ ~~~~~~~~~~~~~~ --- modules/pam_env/pam_env.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/pam_env') diff --git a/modules/pam_env/pam_env.c b/modules/pam_env/pam_env.c index d2d12ad6..01c707fd 100644 --- a/modules/pam_env/pam_env.c +++ b/modules/pam_env/pam_env.c @@ -388,7 +388,7 @@ static int read_file(const pam_handle_t *pamh, const char*filename, char ***line } size_t i = 0; - *lines = malloc((i + 1)* sizeof(char**)); + *lines = malloc((i + 1)* sizeof(char*)); if (*lines == NULL) { pam_syslog(pamh, LOG_ERR, "Cannot allocate memory."); (void) fclose(conf); @@ -398,7 +398,7 @@ static int read_file(const pam_handle_t *pamh, const char*filename, char ***line while (_assemble_line(conf, buffer, BUF_SIZE) > 0) { char **tmp = NULL; D(("Read line: %s", buffer)); - tmp = realloc(*lines, (++i + 1) * sizeof(char**)); + tmp = realloc(*lines, (++i + 1) * sizeof(char*)); if (tmp == NULL) { pam_syslog(pamh, LOG_ERR, "Cannot allocate memory."); (void) fclose(conf); -- cgit v1.2.3