Skip to content

Commit 4d16167

Browse files
committed
Fixes NULL exception on REST message
1 parent d95cea5 commit 4d16167

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

doc/31-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
2121
* [#282](https://github.com/Icinga/icinga-powershell-framework/issues/282) Fixes issue on `System.Text.StringBuilder` which fails to initialize properly on some older Windows systems
2222
* [#284](https://github.com/Icinga/icinga-powershell-framework/issues/284) Fixes exception while creating default threshold objects
2323
* [#285](https://github.com/Icinga/icinga-powershell-framework/issues/285) Fixes plain Icinga 2 conf generation for commands, which was caused by a new exception output for additional output
24+
* [#293](https://github.com/Icinga/icinga-powershell-framework/pull/293) Fixes crash on REST-Api for NULL values while parsing the REST message
2425

2526
## 1.5.0 (2021-06-02)
2627

lib/webserver/Read-IcingaRESTMessage.psm1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ function Read-IcingaRESTMessage()
5454
}
5555

5656
# Header
57-
$Request.Add( 'Header', @{} );
58-
$SplitString = $RestMessage.split("`r`n");
57+
$Request.Add( 'Header', @{ } );
58+
$SplitString = $RestMessage.Split("`r`n");
59+
5960
foreach ( $SingleString in $SplitString ) {
60-
if ( ([string]::IsNullOrEmpty($SingleString) -eq $FALSE) -And ($SingleString -match '^{.+' -eq $FALSE) ) {
61+
if ( ([string]::IsNullOrEmpty($SingleString) -eq $FALSE) -And ($SingleString -match '^{.+' -eq $FALSE) -And $SingleString.Contains(':') -eq $TRUE ) {
6162
$SingleSplitString = $SingleString.Split(':', 2);
6263
$Request.Header.Add( $SingleSplitString[0], $SingleSplitString[1].Trim());
6364
}
@@ -69,7 +70,10 @@ function Read-IcingaRESTMessage()
6970

7071
# Body
7172
$RestMessage -match '(\{(.*\n)*}|\{.*\})' | Out-Null;
72-
$Request.Add('Body', $Matches[1]);
73+
74+
if ($null -ne $Matches) {
75+
$Request.Add('Body', $Matches[1]);
76+
}
7377

7478
# We received a content length, but couldnt load the body. Some clients will send the body as separate message
7579
# Lets try to read the body content

0 commit comments

Comments
 (0)