#ifdef HAVE_GETDOMAINNAME
/* get the domain name (if any) */
if (!initialized) {
- domain = (char *) emalloc(MAXHOSTNAMELEN);
- if (getdomainname(domain, MAXHOSTNAMELEN) == -1 || *domain == '\0') {
+ domain = (char *) emalloc(MAXHOSTNAMELEN + 1);
+ if (getdomainname(domain, MAXHOSTNAMELEN + 1) == -1 || *domain == '\0') {
efree(domain);
domain = NULL;
}
int sudo_mode;
char **envp;
{
- char *p, **ep, thost[MAXHOSTNAMELEN];
+ char *p, **ep, thost[MAXHOSTNAMELEN + 1];
int nohostname;
/* Sanity check command from user. */
if (nohostname)
user_host = user_shost = "localhost";
else {
+ thost[sizeof(thost) - 1] = '\0';
user_host = estrdup(thost);
if (def_fqdn) {
/* Defer call to set_fqdn() until log_error() is safe. */
struct cmndspec *cs;
struct privilege *priv;
struct userspec *us;
- char *p, *grfile, *pwfile, *runas_group, *runas_user, hbuf[MAXHOSTNAMELEN];
+ char *p, *grfile, *pwfile, *runas_group, *runas_user;
+ char hbuf[MAXHOSTNAMELEN + 1];
int ch, dflag, rval, matched;
#ifdef YYDEBUG
extern int yydebug;
if (user_host == NULL) {
if (gethostname(hbuf, sizeof(hbuf)) != 0)
error(1, "gethostname");
+ hbuf[sizeof(hbuf) - 1] = '\0';
user_host = hbuf;
}
if ((p = strchr(user_host, '.'))) {