From 8252476fc8c8bdcacbea41f886f085746df9016a Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 8 Jun 2021 11:49:03 +0200 Subject: tests/mock_*.c: Mark unused function arguments as such. This resolves: mock_pam.c: In function 'fake_conv': mock_pam.c:24:20: error: unused parameter 'num_msg' [-Werror=unused-parameter] 24 | int fake_conv (int num_msg, const struct pam_message **msg, | ~~~~^~~~~~~ mock_pam.c:25:39: error: unused parameter 'appdata_ptr' [-Werror=unused-parameter] 25 | struct pam_response **resp, void *appdata_ptr) | ~~~~~~^~~~~~~~~~~ cc1: all warnings being treated as errors --- tests/mock_pam.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/mock_pam.c') diff --git a/tests/mock_pam.c b/tests/mock_pam.c index 9111092..10f2d80 100644 --- a/tests/mock_pam.c +++ b/tests/mock_pam.c @@ -21,8 +21,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)); -- cgit v1.2.3 From c859cfb399dc00dee24e02dd3acd40d40954c290 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 8 Jun 2021 15:06:30 +0200 Subject: tests/mock_pam.c: Don't leak memory pointed to by 'response'. --- tests/mock_pam.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/mock_pam.c') diff --git a/tests/mock_pam.c b/tests/mock_pam.c index 10f2d80..88dc8d6 100644 --- a/tests/mock_pam.c +++ b/tests/mock_pam.c @@ -45,7 +45,10 @@ int fake_conv (int __attribute__((unused)) num_msg, else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_COMMAND) == 0) response->resp = strdup ("rcommand"); else + { + free(response); return PAM_SYMBOL_ERR; /* leaks... */ + } *resp = response; -- cgit v1.2.3 From a5f1e6f66a82a3630919353a396e77845586121b Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 8 Jun 2021 15:34:27 +0200 Subject: tests/mock_pam.c: Use curly braces for all if-clauses. --- tests/mock_pam.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'tests/mock_pam.c') diff --git a/tests/mock_pam.c b/tests/mock_pam.c index 88dc8d6..21fdde3 100644 --- a/tests/mock_pam.c +++ b/tests/mock_pam.c @@ -29,23 +29,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_X2GO_PROMPT_GUESTLOGIN) == 0) + if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_GUESTLOGIN) == 0) { response->resp = strdup ("guest"); /* IMPORTANT: this needs to be in /etc/passwd */ - else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_USER) == 0) + } else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_USER) == 0) { response->resp = strdup ("ruser"); - else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_HOST) == 0) + } else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_HOST) == 0) { response->resp = strdup ("protocol://rhost/dummy"); - else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_PASSWORD) == 0) + } else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_PASSWORD) == 0) { response->resp = strdup ("password"); - else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_COMMAND) == 0) + } else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_COMMAND) == 0) { response->resp = strdup ("rcommand"); - else - { + } else { free(response); return PAM_SYMBOL_ERR; /* leaks... */ } @@ -71,23 +71,26 @@ pam_handle_t *pam_handle_new (void) int PAM_NONNULL((1)) pam_get_item (const pam_handle_t *pamh, int type, const void **value) { - if (pamh == NULL) + 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; @@ -95,10 +98,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); -- cgit v1.2.3