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

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


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


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:
Status:
RESOLVED FIXED

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:
mcs/class/System.Web/System.Web.Hosting/ApplicationHost.cs

Files that call GetFileSystemEntries() without checking for null:
mcs/class/Compat.ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Tar/TarEntry.cs
mcs/class/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib/Tar/TarEntry.cs
mcs/class/Microsoft.Build.Utilities/Mono.XBuild.Utilities/MSBuildUtils.cs
mcs/class/Mono.Posix/Mono.Unix/UnixDirectoryInfo.cs
mcs/class/System/System.IO/DefaultWatcher.cs
mcs/tools/macpack/MacPack.cs
mcs/tools/monodoc/Lucene.Net/Lucene.Net/SupportClass.cs

Files with a GetFileSystemEntries() that can return null:
mcs/class/corlib/Linux/Linux.cs
mono/metadata/file-io.c

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!