Skip to content

Commit cf700f9

Browse files
authored
Fix nullref exception when a referenceproperty has broken targets and… (#2203)
* Fix nullref exception when a referenceproperty has broken targets and GetSingleValue called on NodeList. * Raise prerelease versions. * Refactor: AuditBlock
1 parent 1f2ad42 commit cf700f9

File tree

15 files changed

+166
-49
lines changed

15 files changed

+166
-49
lines changed

src/ContentRepository.InMemory/SenseNet.ContentRepository.InMemory.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<Version>1.1.1</Version>
5+
<Version>1.1.2-alpha.1</Version>
66
<Authors>kavics,joe,tusmester</Authors>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<Company>Sense/Net Inc.</Company>

src/ContentRepository.MsSql/SenseNet.ContentRepository.MsSql.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<Version>1.1.1</Version>
5+
<Version>1.1.2-alpha.1</Version>
66
<Authors>kavics,tusmester</Authors>
77
<Company>Sense/Net Inc.</Company>
88
<Copyright>Copyright © Sense/Net Inc.</Copyright>

src/ContentRepository/SenseNet.ContentRepository.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<Version>7.8.1</Version>
5+
<Version>7.8.2-alpha.1</Version>
66
<Authors>kavics,joe,tusmester,hashtagnulla</Authors>
77
<Company>Sense/Net Inc.</Company>
88
<Copyright>Copyright © Sense/Net Inc.</Copyright>

src/OData/SenseNet.OData.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<Version>1.1.1</Version>
5+
<Version>1.1.2-alpha.1</Version>
66
<Authors>kavics,tusmester,hashtagnulla</Authors>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<Company>Sense/Net Inc.</Company>

src/OpenApi/SenseNet.OpenApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<Version>1.1.1</Version>
5+
<Version>1.1.2-alpha.1</Version>
66
<Authors>kavics,tusmester</Authors>
77
<Company>Sense/Net Inc.</Company>
88
<Copyright>Copyright © Sense/Net Inc.</Copyright>

src/Services.Core.Install/SenseNet.Services.Core.Install.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>1.1.1</Version>
6+
<Version>1.1.2-alpha.1</Version>
77
<Company>Sense/Net Inc.</Company>
88
<Copyright>Copyright © Sense/Net Inc.</Copyright>
99
<PackageLicenseUrl>https://github.com/SenseNet/sensenet/blob/master/LICENSE</PackageLicenseUrl>

src/Services.Core/SenseNet.Services.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<Version>1.1.1</Version>
5+
<Version>1.1.2-alpha.1</Version>
66
<Authors>kavics,joe,tusmester,hashtagnulla</Authors>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<Company>Sense/Net Inc.</Company>

src/Services.Wopi/SenseNet.Services.Wopi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<Version>1.0.1</Version>
5+
<Version>1.0.2-alpha.1</Version>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Company>Sense/Net Inc.</Company>
88
<Copyright>Copyright © Sense/Net Inc.</Copyright>

src/Storage/Diagnostics/AuditBlock.cs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
using SenseNet.Diagnostics;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
73

8-
namespace SenseNet.Diagnostics
4+
// ReSharper disable once CheckNamespace
5+
namespace SenseNet.Diagnostics;
6+
7+
/// <summary>
8+
/// Ensures that an audit event is logged when the block is disposed.
9+
/// WARNING: writes event only if the code exit unexpectedly from the using block (Successful == false).
10+
/// The successful block must be performed with explicit audit writing.
11+
/// </summary>
12+
public class AuditBlock : IDisposable
913
{
10-
public class AuditBlock : IDisposable
11-
{
12-
private AuditEvent _auditEvent;
13-
private string _operationName;
14-
private IDictionary<string, object> _properties;
15-
private DateTime _startedAt;
14+
private readonly AuditEvent _auditEvent;
15+
private readonly string _operationName;
16+
private readonly IDictionary<string, object> _properties;
17+
private readonly DateTime _startedAt;
1618

17-
public bool Successful { get; set; }
19+
public bool Successful { get; set; }
1820

19-
public AuditBlock(AuditEvent auditEvent, string operationName, IDictionary<string, object> properties)
20-
{
21-
_auditEvent = auditEvent;
22-
_operationName = operationName ?? auditEvent.ToString();
23-
_properties = properties ?? new Dictionary<string, object>();
24-
_startedAt = DateTime.UtcNow;
25-
}
21+
public AuditBlock(AuditEvent auditEvent, string operationName, IDictionary<string, object> properties)
22+
{
23+
_auditEvent = auditEvent;
24+
_operationName = operationName ?? auditEvent.ToString();
25+
_properties = properties ?? new Dictionary<string, object>();
26+
_startedAt = DateTime.UtcNow;
27+
}
2628

27-
public void Dispose()
29+
public void Dispose()
30+
{
31+
if (!Successful)
2832
{
29-
if (!Successful)
30-
{
31-
_properties.Add("Execution", "UNSUCCESSFUL");
32-
_properties.Add("OriginalEvent", _auditEvent);
33-
_properties.Add("StartedAt", _startedAt);
33+
_properties.Add("Execution", "UNSUCCESSFUL");
34+
_properties.Add("OriginalEvent", _auditEvent);
35+
_properties.Add("StartedAt", _startedAt);
3436

35-
var result = new AuditEvent(_auditEvent.AuditCategory, _auditEvent.EventId, "UNSUCCESSFUL " + _auditEvent.AuditCategory, _operationName);
36-
SnLog.WriteAudit(result, _properties);
37-
}
37+
var result = new AuditEvent(_auditEvent.AuditCategory, _auditEvent.EventId, "UNSUCCESSFUL " + _auditEvent.AuditCategory, _operationName);
38+
SnLog.WriteAudit(result, _properties);
3839
}
3940
}
40-
}
41+
}

src/Storage/NodeList.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,18 @@ internal Q GetSingleValue<Q>() where Q : Node
560560
{
561561
if (RawData.Count < 1)
562562
return null;
563-
Node singleNode;
564-
using(new SystemAccount())
565-
singleNode = Node.Load<T>(RawData[0]);
566-
if(!singleNode.Security.HasPermission(AccessProvider.Current.GetCurrentUser(), PermissionType.See))
567-
return null;
568-
return singleNode as Q;
563+
564+
using var systemAccount = new SystemAccount();
565+
566+
var user = AccessProvider.Current.GetCurrentUser();
567+
568+
var singleNode = RawData
569+
.Select(id => Node.Load<T>(id))
570+
.OfType<Q>()
571+
.FirstOrDefault(node =>
572+
node.Security.HasPermission(user, PermissionType.See));
573+
574+
return singleNode;
569575
}
570576
internal void SetSingleValue<Q>(Q value) where Q : Node
571577
{
@@ -580,7 +586,7 @@ internal void SetSingleValue<Q>(Q value) where Q : Node
580586
Modified();
581587
}
582588
}
583-
// Insert or change if value is notn ull.
589+
// Insert or change if value is not null.
584590
else
585591
{
586592
CheckId(value);

0 commit comments

Comments
 (0)