Subject: libpam build problems
To: None <tech-toolchain@netbsd.org>
From: Emmanuel Dreyfus <manu@netbsd.org>
List: tech-toolchain
Date: 02/19/2005 15:35:39
Hi
In order to cross-compile libpam from amd64 to macppc, I had to apply the
attached patches to the source. Does that need to be committed and propagated to
OpenPAM, or is there a lint flag that needs to get rid of in our build system?
There are two distincts problems: sizeof's result is not of type size_t, and
lint will complain about that when sizeof is used as an argument for a function
that wants size_t (e.g.: calloc and friends). Lint shuts up if I add a (size_t)
cast.
Second problem: *data = (void *)(intptr_t)dp->data; bugs because converting a
pointer to int may loose bits. Indeed, but where is the conversion? Removing the
(intptr_t) cast cause lint to shut up.
Index: openpam_borrow_cred.c
===================================================================
RCS file: /cvsroot/src/dist/openpam/lib/openpam_borrow_cred.c,v
retrieving revision 1.3
diff -U4 -r1.3 openpam_borrow_cred.c
--- openpam_borrow_cred.c 8 Jan 2005 07:58:02 -0000 1.3
+++ openpam_borrow_cred.c 19 Feb 2005 14:27:33 -0000
@@ -71,9 +71,9 @@
openpam_log(PAM_LOG_DEBUG, "called with non-zero euid: %d",
(int)geteuid());
RETURNC(PAM_PERM_DENIED);
}
- scred = calloc((size_t)1, sizeof *scred);
+ scred = calloc((size_t)1, (size_t)sizeof *scred);
if (scred == NULL)
RETURNC(PAM_BUF_ERR);
scred->euid = geteuid();
scred->egid = getegid();
Index: openpam_configure.c
===================================================================
RCS file: /cvsroot/src/dist/openpam/lib/openpam_configure.c,v
retrieving revision 1.3
diff -U4 -r1.3 openpam_configure.c
--- openpam_configure.c 30 Dec 2004 02:25:51 -0000 1.3
+++ openpam_configure.c 19 Feb 2005 14:27:33 -0000
@@ -192,9 +192,9 @@
continue;
}
/* allocate new entry */
- if ((this = calloc((size_t)1, sizeof *this)) == NULL)
+ if ((this = calloc((size_t)1, (size_t)sizeof *this)) == NULL)
goto syserr;
/* control flag */
for (ctlf = 0; ctlf < PAM_NUM_CONTROL_FLAGS; ++ctlf)
@@ -228,9 +228,10 @@
while (*q != '\0') {
++this->optc;
q = next_word(q);
}
- this->optv = calloc((size_t)(this->optc + 1), sizeof(char *));
+ this->optv = calloc((size_t)(this->optc + 1),
+ (size_t)sizeof(char *));
if (this->optv == NULL)
goto syserr;
for (i = 0; i < this->optc; ++i) {
if ((this->optv[i] = dup_word(p)) == NULL)
Index: openpam_dynamic.c
===================================================================
RCS file: /cvsroot/src/dist/openpam/lib/openpam_dynamic.c,v
retrieving revision 1.3
diff -U4 -r1.3 openpam_dynamic.c
--- openpam_dynamic.c 3 Jan 2005 17:21:48 -0000 1.3
+++ openpam_dynamic.c 19 Feb 2005 14:27:33 -0000
@@ -62,9 +62,9 @@
void *dlh;
int i;
dlh = NULL;
- if ((module = calloc((size_t)1, sizeof *module)) == NULL)
+ if ((module = calloc((size_t)1, (size_t)sizeof *module)) == NULL)
goto buf_err;
/* Prepend the standard prefix if not an absolute pathname. */
if (path[0] != '/')
Index: openpam_set_option.c
===================================================================
RCS file: /cvsroot/src/dist/openpam/lib/openpam_set_option.c,v
retrieving revision 1.2
diff -U4 -r1.2 openpam_set_option.c
--- openpam_set_option.c 8 Jan 2005 07:58:02 -0000 1.2
+++ openpam_set_option.c 19 Feb 2005 14:27:33 -0000
@@ -85,9 +85,10 @@
if (asprintf(&opt, "%.*s=%s", (int)len, option, value) < 0)
RETURNC(PAM_BUF_ERR);
if (i == cur->optc) {
/* add */
- optv = realloc(cur->optv, sizeof(char *) * (cur->optc + 2));
+ optv = realloc(cur->optv,
+ (size_t)sizeof(char *) * (cur->optc + 2));
if (optv == NULL) {
FREE(opt);
RETURNC(PAM_BUF_ERR);
}
Index: openpam_ttyconv.c
===================================================================
RCS file: /cvsroot/src/dist/openpam/lib/openpam_ttyconv.c,v
retrieving revision 1.5
diff -U4 -r1.5 openpam_ttyconv.c
--- openpam_ttyconv.c 1 Feb 2005 13:20:25 -0000 1.5
+++ openpam_ttyconv.c 19 Feb 2005 14:27:33 -0000
@@ -115,18 +115,18 @@
if (error == EINTR)
fputs(" timeout!", stderr);
if (error || eof) {
fputs("\n", stderr);
- memset(buf, 0, sizeof(buf));
+ memset(buf, 0, (size_t)sizeof(buf));
return (NULL);
}
/* trim trailing whitespace */
for (len = strlen(buf); len > 0; --len)
if (buf[len - 1] != '\r' && buf[len - 1] != '\n')
break;
buf[len] = '\0';
retval = strdup(buf);
- memset(buf, 0, sizeof(buf));
+ memset(buf, 0, (size_t)sizeof(buf));
return (retval);
}
static char *
@@ -175,9 +175,9 @@
/*LINTED unused*/
(void)data;
if (n <= 0 || n > PAM_MAX_NUM_MSG)
RETURNC(PAM_CONV_ERR);
- if ((aresp = calloc((size_t)n, sizeof *aresp)) == NULL)
+ if ((aresp = calloc((size_t)n, (size_t)sizeof *aresp)) == NULL)
RETURNC(PAM_BUF_ERR);
for (i = 0; i < n; ++i) {
aresp[i].resp_retcode = 0;
aresp[i].resp = NULL;
@@ -216,9 +216,9 @@
memset(aresp[i].resp, 0, strlen(aresp[i].resp));
FREE(aresp[i].resp);
}
}
- memset(aresp, 0, n * sizeof *aresp);
+ memset(aresp, 0, n * (size_t)sizeof *aresp);
FREE(aresp);
*resp = NULL;
RETURNC(PAM_CONV_ERR);
/*NOTREACHED*/
Index: pam_get_data.c
===================================================================
RCS file: /cvsroot/src/dist/openpam/lib/pam_get_data.c,v
retrieving revision 1.2
diff -U4 -r1.2 pam_get_data.c
--- pam_get_data.c 8 Jan 2005 07:58:02 -0000 1.2
+++ pam_get_data.c 19 Feb 2005 14:27:33 -0000
@@ -59,9 +59,9 @@
if (pamh == NULL)
RETURNC(PAM_SYSTEM_ERR);
for (dp = pamh->module_data; dp != NULL; dp = dp->next) {
if (strcmp(dp->name, module_data_name) == 0) {
- *data = (void *)(intptr_t)dp->data;
+ *data = (void *)dp->data;
RETURNC(PAM_SUCCESS);
}
}
RETURNC(PAM_NO_MODULE_DATA);
Index: pam_getenvlist.c
===================================================================
RCS file: /cvsroot/src/dist/openpam/lib/pam_getenvlist.c,v
retrieving revision 1.2
diff -U4 -r1.2 pam_getenvlist.c
--- pam_getenvlist.c 8 Jan 2005 07:58:02 -0000 1.2
+++ pam_getenvlist.c 19 Feb 2005 14:27:33 -0000
@@ -56,9 +56,9 @@
ENTER();
if (pamh == NULL)
RETURNP(NULL);
- envlist = malloc(sizeof(char *) * (pamh->env_count + 1));
+ envlist = malloc((size_t)sizeof(char *) * (pamh->env_count + 1));
if (envlist == NULL) {
openpam_log(PAM_LOG_ERROR, "%s",
pam_strerror(pamh, PAM_BUF_ERR));
RETURNP(NULL);
Index: pam_putenv.c
===================================================================
RCS file: /cvsroot/src/dist/openpam/lib/pam_putenv.c,v
retrieving revision 1.3
diff -U4 -r1.3 pam_putenv.c
--- pam_putenv.c 8 Jan 2005 07:58:02 -0000 1.3
+++ pam_putenv.c 19 Feb 2005 14:27:33 -0000
@@ -75,9 +75,9 @@
/* grow the environment list if necessary */
if (pamh->env_count == pamh->env_size) {
env = realloc(pamh->env,
- sizeof(char *) * (pamh->env_size * 2 + 1));
+ (size_t)sizeof(char *) * (pamh->env_size * 2 + 1));
if (env == NULL)
RETURNC(PAM_BUF_ERR);
pamh->env = env;
pamh->env_size = pamh->env_size * 2 + 1;
Index: pam_set_data.c
===================================================================
RCS file: /cvsroot/src/dist/openpam/lib/pam_set_data.c,v
retrieving revision 1.2
diff -U4 -r1.2 pam_set_data.c
--- pam_set_data.c 8 Jan 2005 07:58:02 -0000 1.2
+++ pam_set_data.c 19 Feb 2005 14:27:33 -0000
@@ -69,9 +69,9 @@
dp->cleanup = cleanup;
RETURNC(PAM_SUCCESS);
}
}
- if ((dp = malloc(sizeof *dp)) == NULL)
+ if ((dp = malloc((size_t)sizeof *dp)) == NULL)
RETURNC(PAM_BUF_ERR);
if ((dp->name = strdup(module_data_name)) == NULL) {
FREE(dp);
RETURNC(PAM_BUF_ERR);
Index: pam_start.c
===================================================================
RCS file: /cvsroot/src/dist/openpam/lib/pam_start.c,v
retrieving revision 1.3
diff -U4 -r1.3 pam_start.c
--- pam_start.c 8 Jan 2005 07:58:02 -0000 1.3
+++ pam_start.c 19 Feb 2005 14:27:33 -0000
@@ -56,9 +56,9 @@
struct pam_handle *ph;
int r;
ENTER();
- if ((ph = calloc((size_t)1, sizeof *ph)) == NULL)
+ if ((ph = calloc((size_t)1, (size_t)sizeof *ph)) == NULL)
RETURNC(PAM_BUF_ERR);
if ((r = pam_set_item(ph, PAM_SERVICE, service)) != PAM_SUCCESS)
goto fail;
if ((r = pam_set_item(ph, PAM_USER, user)) != PAM_SUCCESS)
Index: pam_strerror.c
===================================================================
RCS file: /cvsroot/src/dist/openpam/lib/pam_strerror.c,v
retrieving revision 1.2
diff -U4 -r1.2 pam_strerror.c
--- pam_strerror.c 12 Dec 2004 08:16:41 -0000 1.2
+++ pam_strerror.c 19 Feb 2005 14:27:34 -0000
@@ -150,9 +150,9 @@
return ("unknown module type");
case PAM_DOMAIN_UNKNOWN:
return ("unknown authentication domain");
default:
- snprintf(unknown, sizeof unknown, "#%d", error_number);
+ snprintf(unknown, (size_t)sizeof unknown, "#%d", error_number);
return (unknown);
}
}
--
Emmanuel Dreyfus
Le cahier de l'admin BSD 2eme ed. est dans toutes les bonnes librairies
http://www.eyrolles.com/Informatique/Livre/9782212114638/livre-bsd.php
manu@netbsd.org