NetBSD Problem Report #14340

Received: (qmail 24384 invoked from network); 24 Oct 2001 21:23:59 -0000
Message-Id: <20011024212335.DBB6111112@www.netbsd.org>
Date: Wed, 24 Oct 2001 14:23:35 -0700 (PDT)
From: cwlh@nortelnetworks.com
Sender: nobody@netbsd.org
Reply-To: cwlh@nortelnetworks.com
To: gnats-bugs@gnats.netbsd.org
Subject: scandir aborts with Segmentation fault (core dumped)
X-Send-Pr-Version: www-1.0

>Number:         14340
>Category:       lib
>Synopsis:       scandir aborts with Segmentation fault (core dumped)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 24 21:24:00 +0000 2001
>Closed-Date:    Wed Oct 24 21:38:09 +0000 2001
>Last-Modified:  Thu Oct 25 01:36:00 +0000 2001
>Originator:     Chris Hobbs
>Release:        1.5.1
>Organization:
Nortel Networks
>Environment:
NetBSD kanNetBsd1 1.5.1 NetBSD 1.5.1 (GENERIC) #56: Mon Jul  2 15:54:23 CEST 2001     he@nsa.uninett.no:/usr/src/sys/arch/i386/compile/GENERIC i386
>Description:
Calls to scandir when the directory does not exist correctly return a
value of -1. Calls to scandir when the directory does exist cause a 
segmentation fault within scandir.
>How-To-Repeat:
Compile and run this program which was written to isolate the problem.


#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/param.h>
#include <stddef.h>

int main();

int main()
    {
    int     n;
    char    cwd[MAXPATHLEN+1];
    struct dirent ***namelist;

    // get our current working directory
    // to use as an example directory

    getcwd(cwd,MAXPATHLEN);
    printf("cwd = <%s>\n",cwd);

    // then go to get the contents
    // of that directory

    printf("Starting scandir\n");
    n = scandir(cwd,namelist,NULL,NULL);
    printf("Back from scandir\n");

    printf("There were %d entries\n",n);

    return 0;
    }

>Fix:
Don't use scandir: use opendir/readdir/closedir instead.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: pooka 
State-Changed-When: Thu Oct 25 00:37:56 EEST 2001 
State-Changed-Why:  
not a bug 

From: Antti Kantee <pooka@iki.fi>
To: cwlh@nortelnetworks.com
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: lib/14340: scandir aborts with Segmentation fault (core dumped)
Date: Thu, 25 Oct 2001 00:37:42 +0300

 On Wed Oct 24 2001 at 14:23:35 -0700, cwlh@nortelnetworks.com wrote:
 > #include <stdio.h>
 > #include <unistd.h>
 > #include <sys/types.h>
 > #include <dirent.h>
 > #include <sys/param.h>
 > #include <stddef.h>
 > 
 > int main();
 > 
 > int main()
 >     {
 >     int     n;
 >     char    cwd[MAXPATHLEN+1];
 >     struct dirent ***namelist;
 > 
 >     // get our current working directory
 >     // to use as an example directory
 > 
 >     getcwd(cwd,MAXPATHLEN);
 >     printf("cwd = <%s>\n",cwd);
 > 
 >     // then go to get the contents
 >     // of that directory
 > 
 >     printf("Starting scandir\n");
 >     n = scandir(cwd,namelist,NULL,NULL);
 >     printf("Back from scandir\n");
 > 
 >     printf("There were %d entries\n",n);
 > 
 >     return 0;
 >     }

 Remove one `*' from ***namelist, and make the call:
 scandir(cwd, &namelist, NULL, NULL);

 As the man page states, you're supposed to give the function a reference
 to where it'll store the the pointer to an array of pointers.

 -- 
 Antti Kantee <pooka@iki.fi>          v          Of course he runs NetBSD
 http://www.iki.fi/pooka/             i            http://www.NetBSD.org/

From: "Martin J. Laubach" <mjl@emsi.priv.at>
To: gnats-bugs@netbsd.org
Cc:  
Subject: Re: lib/14340: scandir aborts with Segmentation fault (core dumped)
Date: Thu, 25 Oct 2001 01:02:44 +0200

 |  Compile and run this program which was written to isolate the problem.

   Under 1.5Y, I cannot reproduce the problem. Does the bug
 experienced have some requirements on the directory scanned,
 like size, number of files in it, path length?

 	mjl


From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
To: cwlh@nortelnetworks.com
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: lib/14340: scandir aborts with Segmentation fault (core dumped)
Date: Thu, 25 Oct 2001 10:34:20 +0900 (JST)

 From: cwlh@nortelnetworks.com
 >     struct dirent ***namelist;

 >     n = scandir(cwd,namelist,NULL,NULL);

 i think they should be like:

 struct dirent **namelist;
 n = scandir(cwd,&namelist,NULL,NULL);

 ---
 YAMAMOTO Takashi<yamt@mwd.biglobe.ne.jp>
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.