[Mono-dev] GetFileSystemEntries() can return null, but very few null checks

Steven Boswell II ulatekh at yahoo.com
Tue Jun 12 02:14:19 UTC 2012

Since no one seems inclined to look at this bug, here's my proposed fix.
The problem seems to be that ves_icall_System_IO_MonoIO_GetFileSystemEntries() can return NULL without setting an error.
So I rewrote the code to create an empty string-array in that case.
My code uses the dreaded "goto", but IMHO that's no worse than a return statement in the middle of a function.  Besides, in assembly language, all we have is goto :-)

Steven Boswell

 From: Steven Boswell II <ulatekh at yahoo.com>
To: "mono-devel-list at lists.ximian.com" <mono-devel-list at lists.ximian.com> 
Sent: Friday, June 8, 2012 5:43 PM
Subject: [Mono-dev] GetFileSystemEntries() can return null, but very few null checks

Today, rather randomly, I got an unhandled NullReferenceException in mcs/class/System/System.IO/DefaultWatcher.cs at line 221 -- "files" was null.  All the places that "files" gets set can't be null, except for the one on line 204, a call to Directory.GetFileSystemEntries().  That led to mcs/class/corlib/System.IO/Directory.cs line 497, which led to mcs/class/corlib/System.IO/MonoIO.cs line 177, which led to a C function called ves_icall_System_IO_MonoIO_GetFileSystemEntries(), which starts at line 319 of mono/metadata/file-io.c .  That function can return null in several different ways.

Looking around, this seems to be a general problem...

Files that call GetFileSystemEntries() and check for null:

Files that call GetFileSystemEntries() without checking for null:

Files with a GetFileSystemEntries() that can return null:

If fixing this is as simple as adding null checks to the affected areas, I can crank that out and submit a patch.  Otherwise, someone more knowledgeable than me needs to look into this.

I don't see any bug reports in either bugzilla.novell.com or bugzilla.xamarin.com about this issue.  I searched "Mono class libraries" and "Mono runtime".  There were a few other issues related to GetFileSystemEntries(), but none that sounded like this.  So I filed one... https://bugzilla.xamarin.com/show_bug.cgi?id=5591 .

Steven Boswell

Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120611/81581aeb/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mio-01-GetFileSystemEntries.patch
Type: application/octet-stream
Size: 1583 bytes
Desc: not available
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120611/81581aeb/attachment-0001.obj>

More information about the Mono-devel-list mailing list