libsessiond: fix unchecked return value in `subsession_get_user_list` 29/285429/1
authorAdam Michalski <a.michalski2@partner.samsung.com>
Mon, 12 Dec 2022 15:02:29 +0000 (16:02 +0100)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Mon, 12 Dec 2022 15:02:29 +0000 (16:02 +0100)
`getpwuid_r`s semantics is a bit tricky: normally it returns 0 and sets
the output parameter (struct passwd **result) accordingly. If no
matching password record was found, it returns 0 and `*result` is set
to NULL. In case of error, an error number is returned, but the
`*result` is also set to NULL. Since for the API client the reason does
not matter, not checking the return value from the `getpwuid_r` syscall
is not an issue (we're returning `SUBSESSION_ERROR_IO_ERROR` in both
cases). However, to satisfy static analysers we have, it's not
necessarily a bad idea to perform an explicit return value check.

Change-Id: Iefaeccd09331cff977b7cc2a449367de7d5c7db1

src/library/src/lib.c

index 4e3eda7c36fa33915834d1a3bbdc2f33510e7367..f47a4265cb9096706454e2d263bcf59ff605d203 100644 (file)
@@ -987,7 +987,8 @@ EXPORT_API int subsession_get_user_list(int session_uid, subsession_user_t **use
                return SUBSESSION_ERROR_OUT_OF_MEMORY;
 
        struct passwd pass_buf, *pass_ptr;
-       getpwuid_r(session_uid, &pass_buf, pw_buf, max_buf_len, &pass_ptr);
+       if (getpwuid_r(session_uid, &pass_buf, pw_buf, max_buf_len, &pass_ptr) != 0)
+               return SUBSESSION_ERROR_IO_ERROR;
        if (!pass_ptr)
                return SUBSESSION_ERROR_IO_ERROR;