Bug 5591 - GetFileSystemEntries() can return null, but very few null checks
Summary: GetFileSystemEntries() can return null, but very few null checks
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-06-08 20:42 UTC by Steve
Modified: 2012-06-19 15:33 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

My patch for the problem (1.55 KB, patch)
2012-06-14 22:11 UTC, Steve

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Steve 2012-06-08 20:42:20 UTC
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.
Comment 1 Steve 2012-06-14 22:11:44 UTC
Created attachment 2063 [details]
My patch for the problem

As far as I can tell, the problem is that ves_icall_System_IO_MonoIO_GetFileSystemEntries() can return null without setting an error.

The following patch is my suggestion for fixing the problem.

I've submitted this patch to the mono-devel mailing list, but have gotten no reply.
Comment 2 Miguel de Icaza [MSFT] 2012-06-19 15:33:30 UTC
Thanks for the patch, applied!