Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Mar 1999 16:54:56 +0700 (TSK)
From:      User Tolik <tolik@sibptus.tomsk.ru>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   kern/10671: setlogin(2) is not correct ?
Message-ID:  <199903190954.QAA20087@sibptus.tomsk.ru>

next in thread | raw e-mail | index | archive | help

>Number:         10671
>Category:       kern
>Synopsis:       setlogin(2) return EINVAL for length of name greather than MAXLOGNAME - 2
>Confidential:   yes
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 19 02:00:00 PST 1999
>Closed-Date:
>Last-Modified:
>Originator:     Anatoly A. Orehovsky
>Release:        FreeBSD 2.2.8-RELEASE i386
>Organization:
>Environment:

	

>Description:

Calling setlogin(2) return EINVAL for length of name param greather than MAXLOGNAME - 2

/sys/kern/kern_prot.c:
int
setlogin(p, uap, retval)
        struct proc *p;
        struct setlogin_args *uap;
        int *retval;
{
        int error;

        if ((error = suser(p->p_ucred, &p->p_acflag)))
                return (error);
        error = copyinstr((caddr_t) uap->namebuf,
            (caddr_t) p->p_pgrp->pg_session->s_login,
            sizeof (p->p_pgrp->pg_session->s_login) - 1, (u_int *)0);
        if (error == ENAMETOOLONG)
                error = EINVAL;
        return (error);
}

Here is :
calling copyinstr with maxlen = MAXLOGNAME - 1. Such setlogin(2) returned EINVAL
for maxlen > MAXLOGNAME - 2. Manpage of setlogin(2) talk nothing about it.
Is this correct ?

	

>How-To-Repeat:

a.c:
#include <unistd.h>
#include <sys/param.h>
#include <stdio.h>

main(){

char name[MAXLOGNAME] = "0123456789a"; /* 11 chars without '\0' < MAXLOGNAME - 1*/

if (setlogin(name)) {
	perror("setlogin");
	exit(1);
}

exit(0);
}

# cc a.c
# ./a.out; echo "Exitcode $?"
setlogin: Invalid argument
Exitcode 1

	

>Fix:

Either correct manpage of setlogin(2), or correct kern_prot.c.
	
	


>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199903190954.QAA20087>