NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/41620: lockf(3) doesn't fail upon invalid input



>Number:         41620
>Category:       lib
>Synopsis:       lockf(3) doesn't fail upon invalid input
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jun 20 09:15:00 +0000 2009
>Originator:     Stathis Kamperis
>Release:        NetBSD 5.0_STABLE
>Organization:
Aristotle University of Thessaloniki
>Environment:
NetBSD voyager 5.0_STABLE NetBSD 5.0_STABLE (MYGENERIC) #5: Fri Jun 19 14:00:32 
EEST 2009  root@voyager:/usr/obj/sys/arch/i386/compile/MYGENERIC i386

>Description:
According to POSIX, issue 6 lockf(3) shall return:

[EINVAL]
The function argument is not one of F_LOCK, F_TLOCK, F_TEST, or F_ULOCK;
-> or size plus the current file offset is less than 0. <-

On the contrary NetBSD reports success (?). JFYI sunOS 5.10 returns the proper 
code. I didn't test on linux/glibc so I can't comment on that.
>How-To-Repeat:
[stathis@voyager ~] cat t_lockf.c
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
        int fd;

        fd = open("./foo", O_RDWR);
        assert(fd != -1);

        /* Just a sanity check. */
        assert(lseek(fd, 0, SEEK_SET) != -1);

        /* Size plus current file offset is less than 0. */
        assert(lockf(fd, F_LOCK, -1) == -1 && errno == EINVAL);

        assert(close(fd) != -1);

        printf("passed\n");

        return (EXIT_SUCCESS);
}
[stathis@voyager ~] gcc t_lockf.c -Wall
[stathis@voyager ~] ls -lh foo
-rw-r--r--  1 stathis  users  1.0K Jun 20 11:52 foo
[stathis@voyager ~] ./a.out 
assertion "lockf(fd, F_LOCK, -1) == -1 && errno == EINVAL" failed: file 
"t_lockf.c", line 19, f
unction "main"
Abort trap (core dumped)
[stathis@voyager ~] 


Am I missing sth ? 
Thanks!
>Fix:



Home | Main Index | Thread Index | Old Index