check memory allocations. add some const
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10042 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
28
appl/su/su.c
28
appl/su/su.c
@@ -107,10 +107,21 @@ usage (int ret)
|
|||||||
exit (ret);
|
exit (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
free_info(struct passwd *p)
|
||||||
|
{
|
||||||
|
free (p->pw_name);
|
||||||
|
free (p->pw_passwd);
|
||||||
|
free (p->pw_dir);
|
||||||
|
free (p->pw_shell);
|
||||||
|
free (p);
|
||||||
|
}
|
||||||
|
|
||||||
static struct passwd*
|
static struct passwd*
|
||||||
make_info(struct passwd *pwd)
|
dup_info(const struct passwd *pwd)
|
||||||
{
|
{
|
||||||
struct passwd *info;
|
struct passwd *info;
|
||||||
|
|
||||||
info = malloc(sizeof(*info));
|
info = malloc(sizeof(*info));
|
||||||
if(info == NULL)
|
if(info == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -121,8 +132,10 @@ make_info(struct passwd *pwd)
|
|||||||
info->pw_dir = strdup(pwd->pw_dir);
|
info->pw_dir = strdup(pwd->pw_dir);
|
||||||
info->pw_shell = strdup(pwd->pw_shell);
|
info->pw_shell = strdup(pwd->pw_shell);
|
||||||
if(info->pw_name == NULL || info->pw_passwd == NULL ||
|
if(info->pw_name == NULL || info->pw_passwd == NULL ||
|
||||||
info->pw_dir == NULL || info->pw_shell == NULL)
|
info->pw_dir == NULL || info->pw_shell == NULL) {
|
||||||
|
free_info (info);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +145,8 @@ static krb5_ccache ccache;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int
|
static int
|
||||||
krb5_verify(struct passwd *login_info, struct passwd *su_info,
|
krb5_verify(const struct passwd *login_info,
|
||||||
|
const struct passwd *su_info,
|
||||||
const char *kerberos_instance)
|
const char *kerberos_instance)
|
||||||
{
|
{
|
||||||
#ifdef KRB5
|
#ifdef KRB5
|
||||||
@@ -307,7 +321,9 @@ main(int argc, char **argv)
|
|||||||
syslog (LOG_ALERT, "NIS attack, user %s has uid 0", su_user);
|
syslog (LOG_ALERT, "NIS attack, user %s has uid 0", su_user);
|
||||||
errx (1, "unknown login %s", su_user);
|
errx (1, "unknown login %s", su_user);
|
||||||
}
|
}
|
||||||
su_info = make_info(pwd);
|
su_info = dup_info(pwd);
|
||||||
|
if (su_info == NULL)
|
||||||
|
errx (1, "malloc: out of memory");
|
||||||
|
|
||||||
#if defined(HAVE_GETLOGIN) && !defined(POSIX_GETLOGIN)
|
#if defined(HAVE_GETLOGIN) && !defined(POSIX_GETLOGIN)
|
||||||
login_user = getlogin();
|
login_user = getlogin();
|
||||||
@@ -316,7 +332,9 @@ main(int argc, char **argv)
|
|||||||
pwd = getpwuid(getuid());
|
pwd = getpwuid(getuid());
|
||||||
if(pwd == NULL)
|
if(pwd == NULL)
|
||||||
errx(1, "who are you?");
|
errx(1, "who are you?");
|
||||||
login_info = make_info(pwd);
|
login_info = dup_info(pwd);
|
||||||
|
if (login_info == NULL)
|
||||||
|
errx (1, "malloc: out of memory");
|
||||||
if(env_flag)
|
if(env_flag)
|
||||||
shell = login_info->pw_shell;
|
shell = login_info->pw_shell;
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user