From 9a8ea03c5629484ca9db1e04c7a51b89b7d0f4b1 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Mon, 7 Jun 2021 22:39:47 +0200 Subject: tests/mock_pam.h: Includ , so that the PAM_NONNULL() macro is defined. --- tests/mock_pam.h | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/mock_pam.h b/tests/mock_pam.h index 7fe0467..df837df 100644 --- a/tests/mock_pam.h +++ b/tests/mock_pam.h @@ -11,6 +11,7 @@ #define __MOCK_PAM_H__ #define LIBPAM_COMPILE +#include #include #include #include -- cgit v1.2.3 From c55139bfaabd3e5112486716f262936e85a2fb18 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 8 Jun 2021 11:43:55 +0200 Subject: tests/mock_*.c: Mark unused function arguments as such. This resolves: mock_pam.c: In function 'fake_conv': mock_pam.c:22:20: error: unused parameter 'num_msg' [-Werror=unused-parameter] 22 | int fake_conv (int num_msg, const struct pam_message **msg, | ~~~~^~~~~~~ mock_pam.c:23:39: error: unused parameter 'appdata_ptr' [-Werror=unused-parameter] 23 | struct pam_response **resp, void *appdata_ptr) | ~~~~~~^~~~~~~~~~~ mock_pam.c: In function 'fake_conv_empty_password': mock_pam.c:51:35: error: unused parameter 'num_msg' [-Werror=unused-parameter] 51 | int fake_conv_empty_password (int num_msg, const struct pam_message **msg, | ~~~~^~~~~~~ mock_pam.c:52:39: error: unused parameter 'appdata_ptr' [-Werror=unused-parameter] 52 | struct pam_response **resp, void *appdata_ptr) | ~~~~~~^~~~~~~~~~~ cc1: all warnings being treated as errors --- tests/mock_guest.c | 23 ++++++++++++++--------- tests/mock_pam.c | 12 ++++++++---- 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/mock_guest.c b/tests/mock_guest.c index 7673995..218f30e 100644 --- a/tests/mock_guest.c +++ b/tests/mock_guest.c @@ -22,39 +22,44 @@ static struct passwd guest = { "guest", "/tmp", "/bin/true" }; struct passwd * -getpwnam (const char *username) +getpwnam (const char __attribute__((unused)) *username) { return &guest; } int -setgroups(size_t size, const gid_t *list) +setgroups(size_t __attribute__((unused)) size, + const gid_t __attribute__((unused)) *list) { errno = EPERM; return -1; } int -setgid(gid_t gid) +setgid(gid_t __attribute__((unused)) gid) { return 0; } int -setuid(uid_t uid) +setuid(uid_t __attribute__((unused)) uid) { return 0; } int -setegid(gid_t gid) +setegid(gid_t __attribute__((unused)) gid) { return 0; } int -seteuid(uid_t uid) +seteuid(uid_t __attribute__((unused)) uid) { return 0; } -int chmod(const char *path, mode_t mode) +int chmod(const char __attribute__((unused)) *path, + mode_t __attribute__((unused)) mode) { return 0; } -int chown(const char *path, uid_t owner, gid_t group) +int chown(const char __attribute__((unused)) *path, + uid_t __attribute__((unused)) owner, + gid_t __attribute__((unused)) group) { return 0; } -int execvp(const char *file, char *const argv[]) +int execvp(const char __attribute__((unused)) *file, + char __attribute__((unused)) *const argv[]) { return 0; } diff --git a/tests/mock_pam.c b/tests/mock_pam.c index ce57973..e1b7324 100644 --- a/tests/mock_pam.c +++ b/tests/mock_pam.c @@ -19,8 +19,10 @@ struct pam_handle { /* note: the other fields have been omitted */ }; -int fake_conv (int num_msg, const struct pam_message **msg, - struct pam_response **resp, void *appdata_ptr) +int fake_conv (int __attribute__((unused)) num_msg, + const struct pam_message **msg, + struct pam_response **resp, + void __attribute__((unused)) *appdata_ptr) { struct pam_response *response = NULL; response = malloc (sizeof (struct pam_response)); @@ -48,8 +50,10 @@ int fake_conv (int num_msg, const struct pam_message **msg, return PAM_SUCCESS; } -int fake_conv_empty_password (int num_msg, const struct pam_message **msg, - struct pam_response **resp, void *appdata_ptr) +int fake_conv_empty_password (int __attribute__((unused)) num_msg, + const struct pam_message **msg, + struct pam_response **resp, + void __attribute__((unused)) *appdata_ptr) { struct pam_response *response = NULL; response = malloc (sizeof (struct pam_response)); -- cgit v1.2.3 From 33871cdd77a9a3f4f0146bdd9aa2d05c4618efa6 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 8 Jun 2021 15:50:50 +0200 Subject: tests/mock_pam.c: Don't leak memory pointed to by 'response'. --- tests/mock_pam.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/mock_pam.c b/tests/mock_pam.c index e1b7324..71e0f71 100644 --- a/tests/mock_pam.c +++ b/tests/mock_pam.c @@ -42,8 +42,10 @@ int fake_conv (int __attribute__((unused)) num_msg, response->resp = strdup ("password"); else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_DOMAIN) == 0) response->resp = strdup ("domain"); - else + else { + free(response); return PAM_SYMBOL_ERR; /* leaks... */ + } *resp = response; @@ -73,8 +75,10 @@ int fake_conv_empty_password (int __attribute__((unused)) num_msg, response->resp = strdup (""); else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_DOMAIN) == 0) response->resp = strdup ("domain"); - else + else { + free(response); return PAM_SYMBOL_ERR; /* leaks... */ + } *resp = response; -- cgit v1.2.3 From aa69592eff0ec4bda76c8c3d3cbbafe3149b5131 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 8 Jun 2021 15:54:38 +0200 Subject: tests/mock_pam.c: Use curly braces for all if-clauses. --- tests/mock_pam.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'tests') diff --git a/tests/mock_pam.c b/tests/mock_pam.c index 71e0f71..f32d95f 100644 --- a/tests/mock_pam.c +++ b/tests/mock_pam.c @@ -27,22 +27,23 @@ int fake_conv (int __attribute__((unused)) num_msg, struct pam_response *response = NULL; response = malloc (sizeof (struct pam_response)); - if (response == NULL) + if (response == NULL) { return PAM_BUF_ERR; + } response->resp_retcode = 0; - if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_GUESTLOGIN) == 0) + if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_GUESTLOGIN) == 0) { response->resp = strdup ("guest"); /* IMPORTANT: this needs to be in /etc/passwd */ - else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_USER) == 0) + } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_USER) == 0) { response->resp = strdup ("ruser"); - else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_HOST) == 0) + } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_HOST) == 0) { response->resp = strdup ("protocol://rhost/dummy"); - else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_PASSWORD) == 0) + } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_PASSWORD) == 0) { response->resp = strdup ("password"); - else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_DOMAIN) == 0) + } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_DOMAIN) == 0) { response->resp = strdup ("domain"); - else { + } else { free(response); return PAM_SYMBOL_ERR; /* leaks... */ } @@ -65,17 +66,17 @@ int fake_conv_empty_password (int __attribute__((unused)) num_msg, response->resp_retcode = 0; - if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_GUESTLOGIN) == 0) + if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_GUESTLOGIN) == 0) { response->resp = strdup ("guest"); /* IMPORTANT: this needs to be in /etc/passwd */ - else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_USER) == 0) + } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_USER) == 0) { response->resp = strdup ("ruser"); - else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_HOST) == 0) + } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_HOST) == 0) { response->resp = strdup ("protocol://rhost/dummy"); - else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_PASSWORD) == 0) + } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_PASSWORD) == 0) { response->resp = strdup (""); - else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_DOMAIN) == 0) + } else if (strcmp((*msg)->msg, PAM_FREERDP2_PROMPT_DOMAIN) == 0) { response->resp = strdup ("domain"); - else { + } else { free(response); return PAM_SYMBOL_ERR; /* leaks... */ } @@ -117,20 +118,22 @@ int PAM_NONNULL((1)) pam_get_item (const pam_handle_t *pamh, int type, const voi if (pamh == NULL) return PAM_SYSTEM_ERR; - if (type == PAM_CONV) + if (type == PAM_CONV) { *value = pamh->conv; - else if (pamh->item[type] != NULL) + } else if (pamh->item[type] != NULL) { *value = pamh->item[type]; - else + } else { *value = NULL; /* will result in a prompt conversation */ + } return PAM_SUCCESS; } int PAM_NONNULL((1)) pam_set_item (pam_handle_t *pamh, int type, const void *value) { - if (pamh == NULL) + if (pamh == NULL) { return PAM_SYSTEM_ERR; + } void **slot, *tmp; size_t nsize, osize; @@ -138,10 +141,12 @@ int PAM_NONNULL((1)) pam_set_item (pam_handle_t *pamh, int type, const void *val slot = &pamh->item[type]; osize = nsize = 0; - if (*slot != NULL) + if (*slot != NULL) { osize = strlen((const char *)*slot) + 1; - if (value != NULL) + } + if (value != NULL) { nsize = strlen((const char *)value) + 1; + } if (*slot != NULL) { memset(*slot, 0xd0, osize); @@ -149,8 +154,9 @@ int PAM_NONNULL((1)) pam_set_item (pam_handle_t *pamh, int type, const void *val } if (value != NULL) { - if ((tmp = malloc(nsize)) == NULL) + if ((tmp = malloc(nsize)) == NULL) { return PAM_BUF_ERR; + } memcpy(tmp, value, nsize); } else { tmp = NULL; -- cgit v1.2.3 From 0294977b5458ee2c0ba77b6b2b94fb4a4d6a1310 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 8 Jun 2021 15:55:28 +0200 Subject: tests/mock_guest.c: Use same integer type (long unsigned int) for comparing string length returned by snprintf() and a sizeof() return value. --- tests/mock_guest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mock_guest.c b/tests/mock_guest.c index 218f30e..4d10bfb 100644 --- a/tests/mock_guest.c +++ b/tests/mock_guest.c @@ -89,7 +89,7 @@ socket_sucker () serv_addr.sun_family = AF_UNIX; - int printsize = snprintf(serv_addr.sun_path, sizeof(serv_addr.sun_path) - 1, "%s/%s", home, ".freerdp2-socket"); + unsigned long int printsize = (unsigned long int)snprintf(serv_addr.sun_path, sizeof(serv_addr.sun_path) - 1, "%s/%s", home, ".freerdp2-socket"); if (printsize > sizeof(serv_addr.sun_path) - 1 || printsize < 0) { return -1; } -- cgit v1.2.3