summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2020-03-16 21:02:18 +0000
committerDmitry V. Levin <ldv@altlinux.org>2020-03-19 18:40:16 +0000
commit1181e0590c9f059c40b71718d4fb3b6c339f65db (patch)
tree96da444742d360992e91d6f937e461892ff5f1c0 /modules
parenta8b4dce7b53d73de372e150028c970ee0a2a2e97 (diff)
Use PAM_ARRAY_SIZE
Replace all instances of sizeof(x) / sizeof(*x) with PAM_ARRAY_SIZE(x) which is less error-prone and implements an additional type check. * libpam/pam_handlers.c: Include "pam_inline.h". (_pam_open_config_file): Use PAM_ARRAY_SIZE. * modules/pam_exec/pam_exec.c: Include "pam_inline.h". (call_exec): Use PAM_ARRAY_SIZE. * modules/pam_namespace/pam_namespace.c: Include "pam_inline.h". (filter_mntopts): Use PAM_ARRAY_SIZE. * modules/pam_timestamp/hmacfile.c: Include "pam_inline.h". (testvectors): Use PAM_ARRAY_SIZE. * modules/pam_xauth/pam_xauth.c: Include "pam_inline.h". (run_coprocess, pam_sm_open_session): Use PAM_ARRAY_SIZE. * tests/tst-pam_get_item.c: Include "pam_inline.h". (main): Use PAM_ARRAY_SIZE. * tests/tst-pam_set_item.c: Likewise. * xtests/tst-pam_pwhistory1.c: Likewise. * xtests/tst-pam_time1.c: Likewise.
Diffstat (limited to 'modules')
-rw-r--r--modules/pam_exec/pam_exec.c3
-rw-r--r--modules/pam_namespace/pam_namespace.c5
-rw-r--r--modules/pam_timestamp/hmacfile.c4
-rw-r--r--modules/pam_xauth/pam_xauth.c5
4 files changed, 11 insertions, 6 deletions
diff --git a/modules/pam_exec/pam_exec.c b/modules/pam_exec/pam_exec.c
index 6cad16e4..f1a1bc29 100644
--- a/modules/pam_exec/pam_exec.c
+++ b/modules/pam_exec/pam_exec.c
@@ -59,6 +59,7 @@
#include <security/pam_modutil.h>
#include <security/pam_ext.h>
#include <security/_pam_macros.h>
+#include "pam_inline.h"
#define ENV_ITEM(n) { (n), #n }
static struct {
@@ -414,7 +415,7 @@ call_exec (const char *pam_type, pam_handle_t *pamh,
envlist = pam_getenvlist(pamh);
for (envlen = 0; envlist[envlen] != NULL; ++envlen)
/* nothing */ ;
- nitems = sizeof(env_items) / sizeof(*env_items);
+ nitems = PAM_ARRAY_SIZE(env_items);
/* + 2 because of PAM_TYPE and NULL entry */
tmp = realloc(envlist, (envlen + nitems + 2) * sizeof(*envlist));
if (tmp == NULL)
diff --git a/modules/pam_namespace/pam_namespace.c b/modules/pam_namespace/pam_namespace.c
index 155d3965..51f7ac15 100644
--- a/modules/pam_namespace/pam_namespace.c
+++ b/modules/pam_namespace/pam_namespace.c
@@ -35,6 +35,7 @@
#define _ATFILE_SOURCE
#include "pam_cc_compat.h"
+#include "pam_inline.h"
#include "pam_namespace.h"
#include "argv_parse.h"
@@ -260,7 +261,7 @@ static int filter_mntopts(const char *opts, char **filtered,
do {
size_t len;
- int i;
+ unsigned int i;
end = strchr(opts, ',');
if (end == NULL) {
@@ -269,7 +270,7 @@ static int filter_mntopts(const char *opts, char **filtered,
len = end - opts;
}
- for (i = 0; i < (int)(sizeof(mntflags)/sizeof(mntflags[0])); i++) {
+ for (i = 0; i < PAM_ARRAY_SIZE(mntflags); i++) {
if (mntflags[i].len != len)
continue;
if (memcmp(mntflags[i].name, opts, len) == 0) {
diff --git a/modules/pam_timestamp/hmacfile.c b/modules/pam_timestamp/hmacfile.c
index 69d39afa..371f814e 100644
--- a/modules/pam_timestamp/hmacfile.c
+++ b/modules/pam_timestamp/hmacfile.c
@@ -33,6 +33,8 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "pam_inline.h"
+
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
@@ -104,7 +106,7 @@ testvectors(void)
"e8e99d0f45237d786d6bbaa7965c7808bbff1a91",
},
};
- for (i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
+ for (i = 0; i < PAM_ARRAY_SIZE(vectors); i++) {
hmac = NULL;
hmac_len = 0;
hmac_sha1_generate(&hmac, &hmac_len,
diff --git a/modules/pam_xauth/pam_xauth.c b/modules/pam_xauth/pam_xauth.c
index ea99bb03..f74a0c98 100644
--- a/modules/pam_xauth/pam_xauth.c
+++ b/modules/pam_xauth/pam_xauth.c
@@ -64,6 +64,7 @@
#endif
#include "pam_cc_compat.h"
+#include "pam_inline.h"
#define DATANAME "pam_xauth_cookie_file"
#define XAUTHENV "XAUTHORITY"
@@ -172,7 +173,7 @@ run_coprocess(pam_handle_t *pamh, const char *input, char **output,
/* Convert the varargs list into a regular array of strings. */
va_start(ap, command);
args[0] = command;
- for (j = 1; j < ((sizeof(args) / sizeof(args[0])) - 1); j++) {
+ for (j = 1; j < PAM_ARRAY_SIZE(args) - 1; j++) {
args[j] = va_arg(ap, const char*);
if (args[j] == NULL) {
break;
@@ -399,7 +400,7 @@ pam_sm_open_session (pam_handle_t *pamh, int flags UNUSED,
if (xauth == NULL) {
size_t j;
- for (j = 0; j < sizeof(xauthpaths)/sizeof(xauthpaths[0]); j++) {
+ for (j = 0; j < PAM_ARRAY_SIZE(xauthpaths); j++) {
if (access(xauthpaths[j], X_OK) == 0) {
xauth = xauthpaths[j];
break;