Subject: bin/36725: fsplit segfaults when user doesnt have correct permissions
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <new.security@gmail.com>
List: netbsd-bugs
Date: 08/02/2007 21:00:01
>Number:         36725
>Category:       bin
>Synopsis:       fsplit segfaults when user doesnt have correct permissions
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 02 21:00:00 +0000 2007
>Originator:     Kevin Massey
>Release:        3.1
>Organization:
>Environment:
NetBSD seedless.regime.gov 3.1_STABLE NetBSD 3.1_STABLE 

>Description:
When you run fsplit without any arguments in a directory that you do not have writing permissions in it will segfault because it is trying to write  a file without checking if you have the correct permissions.
>How-To-Repeat:
run fsplit in a directory you do not have write permissions in.
>Fix:
Index: fsplit.c
===================================================================
RCS file: /cvsroot/src/usr.bin/fsplit/fsplit.c,v
retrieving revision 1.11
diff -u -r1.11 fsplit.c
--- fsplit.c    30 Oct 2004 17:27:28 -0000      1.11
+++ fsplit.c    2 Aug 2007 16:21:39 -0000
@@ -147,8 +147,15 @@
                        exit(1);
                }
        }
-       else
+       else {
+               if((access(".", W_OK)) !=0) {
+                       fprintf(stderr, "Incorrent access user cannot write to directory\n");
+                       exit(1);
+               }
+
                ifp = stdin;
+       }
+
     for(;;) {
        /* look for a temp file that doesn't correspond to an existing file */
        get_name(x, 3);