Overflow protection.

This commit is contained in:
Mats Erik Andersson
2012-10-02 16:31:21 +02:00
parent 6cc00eea32
commit 066ab95148
11 changed files with 52 additions and 21 deletions

View File

@@ -142,7 +142,7 @@ waitdaemon (int nochdir, int noclose, int maxwait)
alarm (maxwait);
pause ();
}
_exit (0);
_exit (EXIT_SUCCESS);
}
if (setsid () == -1)
@@ -163,7 +163,7 @@ waitdaemon (int nochdir, int noclose, int maxwait)
return -1;
default:
_exit (0);
_exit (EXIT_SUCCESS);
}
if (!nochdir)

View File

@@ -136,7 +136,13 @@ logwtmp (char *line, char *name, char *host)
#if defined HAVE_STRUCT_UTMP_UT_HOST || defined HAVE_STRUCT_UTMPX_UT_HOST
strncpy (ut.ut_host, host, sizeof ut.ut_host);
# ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN /* Only utmpx. */
ut.ut_syslen = strlen (host) + 1; /* Including NUL. */
if (strlen (host) < sizeof (ut.ut_host))
ut.ut_syslen = strlen (host) + 1; /* Including NUL. */
else
{
ut.ut_host[sizeof (ut.ut_host) - 1] = '\0';
ut.ut_syslen = sizeof (ut.ut_host);
}
# endif /* UT_SYSLEN */
#endif /* UT_HOST */

View File

@@ -54,7 +54,13 @@ logwtmp (char *line, char *name, char *host)
#ifdef HAVE_STRUCT_UTMPX_UT_HOST
strncpy (ut.ut_host, host, sizeof ut.ut_host);
# ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN
ut.ut_syslen = strlen (host) + 1; /* Including NUL. */
if (strlen (host) < sizeof (ut.ut_host))
ut.ut_syslen = strlen (host) + 1;
else
{
ut.ut_host[sizeof (ut.ut_host) - 1] = '\0';
ut.ut_syslen = sizeof (ut.ut_host);
}
# endif /* UT_SYSLEN */
#endif
#ifdef HAVE_STRUCT_UTMPX_UT_PID

View File

@@ -152,7 +152,7 @@ ttymsg (struct iovec *iov, int iovcnt, char *line, int tmout)
if (forked)
{
close (fd);
_exit (1);
_exit (EXIT_FAILURE);
}
cpid = fork2 ();
if (cpid < 0)
@@ -194,7 +194,7 @@ ttymsg (struct iovec *iov, int iovcnt, char *line, int tmout)
break;
close (fd);
if (forked)
_exit (1);
_exit (EXIT_FAILURE);
snprintf (errbuf, sizeof (errbuf), "%s: %s", device, strerror (errno));
free (device);
return (errbuf);
@@ -203,7 +203,7 @@ ttymsg (struct iovec *iov, int iovcnt, char *line, int tmout)
free (device);
close (fd);
if (forked)
_exit (0);
_exit (EXIT_SUCCESS);
return (NULL);
}
@@ -232,7 +232,7 @@ fork2 (void)
case -1:
_exit (errno); /* Assumes all errnos are <256 */
default: /* Parent. */
_exit (0);
_exit (EXIT_SUCCESS);
}
}

View File

@@ -91,7 +91,13 @@ utmp_init (char *line, char *user, char *id, char *host)
#if defined HAVE_STRUCT_UTMP_UT_HOST || defined HAVE_STRUCT_UTMPX_UT_HOST
strncpy (utx.ut_host, host, sizeof (utx.ut_host));
# ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN /* Only utmpx. */
utx.ut_syslen = strlen (host) + 1;
if (strlen (host) < sizeof (utx.ut_host))
utx.ut_syslen = strlen (host) + 1;
else
{
utx.ut_host[sizeof (utx.ut_host) - 1] = '\0';
utx.ut_syslen = sizeof (utx.ut_host);
}
# endif
#endif /* UT_HOST */
#if defined HAVE_STRUCT_UTMP_UT_LINE || defined HAVE_STRUCT_UTMPX_UT_LINE