Skip to content

Commit

Permalink
runtime: minor bugs fixed in coreclr and libraries (dotnet#97155)
Browse files Browse the repository at this point in the history
* Fixed error: <Pointer, returned from function 'gmtime_r' at filetime.cpp:262, may be NULL and is dereferenced at filetime.cpp:268>. The error was detected using the Svace analyzer maded by ISP RAS.

* Fixed error: <Return value of a function 'PAL_wcsrchr' is dereferenced at process.cpp:2824 without checking for NULL, but it is usually checked for this function (11/12)>. The error was detected using the Svace analyzer maded by ISP RAS.

* Fixed error: <Value sectionRecord, which is result of method invocation with possible null return value, is dereferenced in member access expression sectionRecord.HasLocationInput>. The error was detected using the Svace analyzer maded by ISP RAS.

* Fixed error: <Maybe ecmaCandidateMethod, that created from method with AS-cast should be compared with null instead of method>. The error was detected using the Svace analyzer maded by ISP RAS.

* Update filetime.cpp

* Update process.cpp

* Update MgmtConfigurationRecord.cs

* Update src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/MgmtConfigurationRecord.cs

Co-authored-by: Jan Kotas <jkotas@microsoft.com>

* Update src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/MgmtConfigurationRecord.cs

Co-authored-by: Jan Kotas <jkotas@microsoft.com>

---------

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
  • Loading branch information
2 people authored and tmds committed Jan 23, 2024
1 parent ad22b15 commit a8b071f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/coreclr/pal/src/file/filetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,13 @@ BOOL PALAPI FileTimeToSystemTime( CONST FILETIME * lpFileTime,
#else /* HAVE_GMTIME_R */
UnixSystemTime = gmtime( &UnixFileTime );
#endif /* HAVE_GMTIME_R */

if (!UnixSystemTime)
{
ERROR( "gmtime failed.\n" );
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}

/* Convert unix system time to Windows system time. */
lpSystemTime->wDay = (WORD)UnixSystemTime->tm_mday;

Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/pal/src/thread/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2821,6 +2821,12 @@ CorUnix::InitializeProcessCommandLine(
if (lpwstrFullPath)
{
LPWSTR lpwstr = PAL_wcsrchr(lpwstrFullPath, '/');
if (!lpwstr)
{
ERROR("Invalid full path\n");
palError = ERROR_INTERNAL_ERROR;
goto exit;
}
lpwstr[0] = '\0';
size_t n = PAL_wcslen(lpwstrFullPath) + 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ private uint LookupIbcMethodToken(MetadataType methodMetadataType, uint ibcToken
if (method.Name == methodName)
{
EcmaMethod ecmaCandidateMethod = method as EcmaMethod;
if (method == null)
if (ecmaCandidateMethod == null)
continue;

MetadataReader metadataReader = ecmaCandidateMethod.MetadataReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ internal ConfigurationSection FindImmediateParentSection(ConfigurationSection se

string configKey = section.SectionInformation.SectionName;
SectionRecord sectionRecord = GetSectionRecord(configKey, false);
Debug.Assert(sectionRecord != null);
if (sectionRecord.HasLocationInputs)
{
SectionInput input = sectionRecord.LastLocationInput;
Expand Down

0 comments on commit a8b071f

Please sign in to comment.