Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProxySettings: Long ProxyServerExceptions result in an error #378

Closed
Seth401 opened this issue Jan 30, 2019 · 1 comment · Fixed by #383
Closed

ProxySettings: Long ProxyServerExceptions result in an error #378

Seth401 opened this issue Jan 30, 2019 · 1 comment · Fixed by #383
Assignees
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.

Comments

@Seth401
Copy link

Seth401 commented Jan 30, 2019

Details of the scenario you tried and the problem that is occurring

Using a very "long" ProxyServerExceptions list will lead to an error while trying to apply the configuration. The reason is that the length of the ProxyServerExceptions string currently can't exceed 255 characters as it's converted to a byte.

Verbose logs showing the problem

I'm only including the relevant part.

VERBOSE: [AD]:                            [[ProxySettings]Longbypass] Test-TargetResource: Checking the computer proxy settings to ensure 'Present'.
VERBOSE: [AD]:                            [[ProxySettings]Longbypass] Test-TargetResource: Checking that the computer proxy settings 'DefaultConnectionSettings' are in the desired state.
VERBOSE: [AD]:                            [[ProxySettings]Longbypass] Test-ProxySettings: The proxy setting 'ProxyServerExceptions' value 'b1.com;*.web2.com;*.web3.com;*.web4.com;*.' does not match the desired value '*.example1.com;*.example2.com;*.example3.
com;*.example4.com;*.example5.com;*.example6.com;*.example7.com;*.example8.com;*.example9.com;*.example10.com;*.example11.com;*.example12.com;*.example13.com;*.example14.com;*.example15.com;*.example16.com;*.example17.com'.
VERBOSE: [AD]:                            [[ProxySettings]Longbypass] Test-TargetResource: Computer proxy settings 'DefaultConnectionSettings' are not in the desired state.
VERBOSE: [AD]:                            [[ProxySettings]Longbypass] Test-TargetResource: Checking that the computer proxy settings 'SavedLegacySettings' are in the desired state.
VERBOSE: [AD]:                            [[ProxySettings]Longbypass] Test-ProxySettings: The proxy setting 'ProxyServerExceptions' value 'b1.com;*.web2.com;*.web3.com;*.web4.com;*.' does not match the desired value '*.example1.com;*.example2.com;*.example3.
com;*.example4.com;*.example5.com;*.example6.com;*.example7.com;*.example8.com;*.example9.com;*.example10.com;*.example11.com;*.example12.com;*.example13.com;*.example14.com;*.example15.com;*.example16.com;*.example17.com'.
VERBOSE: [AD]:                            [[ProxySettings]Longbypass] Test-TargetResource: Computer proxy settings 'SavedLegacySettings' are not in the desired state.
VERBOSE: [AD]: LCM:  [ End    Test     ]  [[ProxySettings]Longbypass]  in 0.2190 seconds.
VERBOSE: [AD]: LCM:  [ Start  Set      ]  [[ProxySettings]Longbypass]
VERBOSE: [AD]:                            [[ProxySettings]Longbypass] Set-TargetResource: Applying the computer proxy settings to ensure 'Present'.
VERBOSE: [AD]:                            [[ProxySettings]Longbypass] Set-TargetResource: Enabling computer proxy settings.
Cannot convert value "262" to type "System.Byte". Error: "Value was either too large or too small for an unsigned byte."
    + CategoryInfo          : InvalidArgument: (:) [], CimException
    + FullyQualifiedErrorId : InvalidCastIConvertible
    + PSComputerName        : localhost

Suggested solution to the issue

The responsible line within the ProxySettings DSC resource directly uses the string length. If this exceeds 255 it can't be converted to a byte.
https://github.com/PowerShell/NetworkingDsc/blob/e714098d02654dfa8a3aed6b44430c68cea9fdbf/Modules/NetworkingDsc/DSCResources/MSFT_ProxySettings/MSFT_ProxySettings.psm1#L655

As far as I can tell those 4 bytes can be used to indicate the length but as it is little endian hex you need to convert it to hex and reverse the order for each pair. The following would only be a patch for the write, I didn't check the read but it likely needs to be adjusted as well.

There probably is a better solution to do the conversion.

655c655,662
<         $proxySettings += @($ProxyServerExceptionsString.Length, 0x0, 0x0, 0x0)
---
> 	  $hex = '{0:x8}' -f $ProxyServerExceptionsString.Length
>         $ProxyServerExceptionsStringLength = @()
>         $ProxyServerExceptionsStringLength += @("0x"+($hex[6..7] -join ''))
>         $ProxyServerExceptionsStringLength += @("0x"+($hex[4..5] -join ''))
>         $ProxyServerExceptionsStringLength += @("0x"+($hex[2..3] -join ''))
>         $ProxyServerExceptionsStringLength += @("0x"+($hex[0..1] -join ''))
> 
>         $proxySettings += [Byte[]][Int[]]$ProxyServerExceptionsStringLength

The DSC configuration that is used to reproduce the issue (as detailed as possible)

Using a value of 17 generates a ProxyServerExceptions list that results in a string that's 262 character long. Using a value of 16 results in a string that's 246 characters long.

Configuration LongProxyExample
{
    $bypass = 1..17 | %{ "*.example$_.com" }
    Import-DSCResource -ModuleName NetworkingDsc

    Node localhost
    {
        ProxySettings Longbypass
        {
            IsSingleInstance       = 'Yes'
            ProxyServerExceptions  = $bypass
        }
    }
}

The operating system the target node is running

OsName               : Microsoft Windows Server 2016 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsBuildLabEx    : 14393.1794.amd64fre.rs1_release.171008-1615
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.14393.1884
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.1884
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

6.3.0.0

@PlagueHO PlagueHO added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Feb 2, 2019
@PlagueHO
Copy link
Member

PlagueHO commented Feb 2, 2019

Great catch and thanks for raising this @Seth401 - looks like this one shouldn't be too tough to fix. Happy to take PRs from the community - but otherwise I'll try and get to it as soon as I can (got a few other repos I'm looking after).

@PlagueHO PlagueHO self-assigned this Mar 2, 2019
@PlagueHO PlagueHO added in progress The issue is being actively worked on by someone. and removed help wanted The issue is up for grabs for anyone in the community. labels Mar 2, 2019
PlagueHO added a commit that referenced this issue Mar 4, 2019
MSFT_Proxy - Fix Strings Parameters longer than 255 chars - Fixes #378
@SteveL-MSFT SteveL-MSFT added this to In progress in powershell/dscresources May 14, 2019
@SteveL-MSFT SteveL-MSFT removed this from In progress in powershell/dscresources Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants