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

win_sspi auth info overflows isc_dpb_version1 parameter block [DNET936] #859

Closed
firebird-automations opened this issue Mar 19, 2020 · 10 comments

Comments

@firebird-automations
Copy link

Submitted by: Foodstuffs INCA team (fssi-inca)

Is duplicated by DNET941

Votes: 1

Expected behaviour: .NET provider supports connections with Windows Trusted User authentication.

Actual behaviour: Windows Trusted User authentication connection fails with "Invalid clumplet buffer structure: buffer end before end of clumplet - clumplet too long".

Steps to reproduce:

PS C:\temp> Add-Type -Path FirebirdSql.Data.FirebirdClient.7.5.0.dll
>> $factory = [FirebirdSql.Data.FirebirdClient.FirebirdClientFactory]::Instance
>> $conn = $factory.CreateConnection()
>> $conn.ConnectionString = "Server=dvpapainca01;Port=3051;Database=incastatus;"
>> $conn.Open()
Exception calling "Open" with "0" argument(s): "Invalid clumplet buffer structure: buffer end before end of clumplet - clumplet too long"
At line:5 char:1
+ $conn.Open()
+ ~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FbException

Description:

This appears to be a result of win_sspi auth info overflowing the isc_dpb_version1 block - presumably there is an element to this specific to the Windows domain?
By changing to isc_dpb_version2, the connection succeeds. I've attached a diff for this change below, but it's a naive solution - presumably there would be backwards compatibility issues with a straight switch.

PS C:\temp> Add-Type -Path FirebirdSql.Data.FirebirdClient.7.5.0+isc_dpb_version2.dll
>> $factory = [FirebirdSql.Data.FirebirdClient.FirebirdClientFactory]::Instance
>> $conn = $factory.CreateConnection()
>> $conn.ConnectionString = "Server=dvpapainca01;Port=3051;Database=incastatus;"
>> $conn.Open()

PS C:\temp> $conn
ConnectionString : Server=dvpapainca01;Port=3051;Database=incastatus;
ConnectionTimeout : 15
Database : incastatus
DataSource : dvpapainca01
ServerVersion : WI-V3.0.5.33220 Firebird 3.0/tcp (DVPAPAINCA01)/P13
State : Open
PacketSize : 8192
Site :
Container :

diff --git a/Provider/src/FirebirdSql.Data.FirebirdClient/Common/DatabaseParameterBuffer.cs b/Provider/src/FirebirdSql.Data.FirebirdClient/Common/DatabaseParameterBuffer.cs
index 4f10ee72..aa851e6e 100644
--- a/Provider/src/FirebirdSql.Data.FirebirdClient/Common/DatabaseParameterBuffer.cs
+++ b/Provider/src/FirebirdSql.Data.FirebirdClient/Common/DatabaseParameterBuffer.cs
@@ -31,21 +31,21 @@ namespace FirebirdSql.Data.Common
public void Append(int type, byte value)
{
WriteByte(type);
- WriteByte(1);
+ Write((int)1);
Write(value);
}

	public void Append\(int type, short value\)
	\{
		WriteByte\(type\);

- WriteByte(2);
+ Write((int)2);
Write(value);
}

	public void Append\(int type, int value\)
	\{
		WriteByte\(type\);

- WriteByte((byte)4);
+ Write((int)4);
Write(value);
}

@@ -57,7 +57,7 @@ namespace FirebirdSql.Data.Common
public void Append(int type, byte[] buffer)
{
WriteByte(type);
- WriteByte(buffer.Length);
+ Write((int)buffer.Length);
Write(buffer);
}
}
diff --git a/Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs b/Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs
index 65c5b4e7..76a0cf0a 100644
--- a/Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs
+++ b/Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs
@@ -224,6 +224,7 @@ namespace FirebirdSql.Data.Common
#⁠region Database Parameter Block

	public const int isc\_dpb\_version1 = 1;

+ public const int isc_dpb_version2 = 2; // sjd: support >256-byte entries - requires FB3 / protocol 13
public const int isc_dpb_cdd_pathname = 1;
public const int isc_dpb_allocation = 2;
public const int isc_dpb_journal = 3;
diff --git a/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs b/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs
index f6d38a65..aa79ab62 100644
--- a/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs
+++ b/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs
@@ -73,7 +73,7 @@ namespace FirebirdSql.Data.FirebirdClient
{
var dpb = new DatabaseParameterBuffer();

- dpb.Append(IscCodes.isc_dpb_version1);
+ dpb.Append(IscCodes.isc_dpb_version2);
dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });
dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });
if (!string.IsNullOrEmpty(options.UserID))
diff --git a/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs b/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs
index e4890dcd..cec4413d 100644
--- a/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs
+++ b/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs
@@ -402,7 +402,7 @@ namespace FirebirdSql.Data.FirebirdClient
{
var dpb = new DatabaseParameterBuffer();

- dpb.Append(IscCodes.isc_dpb_version1);
+ dpb.Append(IscCodes.isc_dpb_version2);
dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });
dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });
dpb.Append(IscCodes.isc_dpb_lc_ctype, options.Charset);

Commits: 2679471

@firebird-automations
Copy link
Author

Modified by: Foodstuffs INCA team (fssi-inca)

description: Expected behaviour: .NET provider supports connections with Windows Trusted User authentication.

Actual behaviour: Windows Trusted User authentication connection fails with "Invalid clumplet buffer structure: buffer end before end of clumplet - clumplet too long".

Steps to reproduce:

PS C:\temp> Add-Type -Path FirebirdSql.Data.FirebirdClient.7.5.0.dll
>> $factory = [FirebirdSql.Data.FirebirdClient.FirebirdClientFactory]::Instance
>> $conn = $factory.CreateConnection()
>> $conn.ConnectionString = "Server=dvpapainca01;Port=3051;Database=incastatus;"
>> $conn.Open()
Exception calling "Open" with "0" argument(s): "Invalid clumplet buffer structure: buffer end before end of clumplet - clumplet too long"
At line:5 char:1
+ $conn.Open()
+ ~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FbException

Description:

This appears to be a result of win_sspi auth info overflowing the isc_dpb_version1 block - presumably there is a Windows domain specific element to this?
By changing to isc_dpb_version2, the connection succeeds. I've attached a diff for this change below, but it's a naive solution - presumably there would be backwards compatibility issues with a straight switch.

PS C:\temp> Add-Type -Path FirebirdSql.Data.FirebirdClient.7.5.0+isc_dpb_version2.dll
>> $factory = [FirebirdSql.Data.FirebirdClient.FirebirdClientFactory]::Instance
>> $conn = $factory.CreateConnection()
>> $conn.ConnectionString = "Server=dvpapainca01;Port=3051;Database=incastatus;"
>> $conn.Open()

PS C:\temp> $conn
ConnectionString : Server=dvpapainca01;Port=3051;Database=incastatus;
ConnectionTimeout : 15
Database : incastatus
DataSource : dvpapainca01
ServerVersion : WI-V3.0.5.33220 Firebird 3.0/tcp (DVPAPAINCA01)/P13
State : Open
PacketSize : 8192
Site :
Container :

diff --git a/Provider/src/FirebirdSql.Data.FirebirdClient/Common/DatabaseParameterBuffer.cs b/Provider/src/FirebirdSql.Data.FirebirdClient/Common/DatabaseParameterBuffer.cs
index 4f10ee72..aa851e6e 100644
--- a/Provider/src/FirebirdSql.Data.FirebirdClient/Common/DatabaseParameterBuffer.cs
+++ b/Provider/src/FirebirdSql.Data.FirebirdClient/Common/DatabaseParameterBuffer.cs
@@ -31,21 +31,21 @@ namespace FirebirdSql.Data.Common
public void Append(int type, byte value)
{
WriteByte(type);
- WriteByte(1);
+ Write((int)1);
Write(value);
}

	public void Append\(int type, short value\)
	\{
		WriteByte\(type\);

- WriteByte(2);
+ Write((int)2);
Write(value);
}

	public void Append\(int type, int value\)
	\{
		WriteByte\(type\);

- WriteByte((byte)4);
+ Write((int)4);
Write(value);
}

@@ -57,7 +57,7 @@ namespace FirebirdSql.Data.Common
public void Append(int type, byte[] buffer)
{
WriteByte(type);
- WriteByte(buffer.Length);
+ Write((int)buffer.Length);
Write(buffer);
}
}
diff --git a/Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs b/Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs
index 65c5b4e7..76a0cf0a 100644
--- a/Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs
+++ b/Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs
@@ -224,6 +224,7 @@ namespace FirebirdSql.Data.Common
#⁠region Database Parameter Block

	public const int isc\_dpb\_version1 = 1;

+ public const int isc_dpb_version2 = 2; // sjd: support >256-byte entries - requires FB3 / protocol 13
public const int isc_dpb_cdd_pathname = 1;
public const int isc_dpb_allocation = 2;
public const int isc_dpb_journal = 3;
diff --git a/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs b/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs
index f6d38a65..aa79ab62 100644
--- a/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs
+++ b/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs
@@ -73,7 +73,7 @@ namespace FirebirdSql.Data.FirebirdClient
{
var dpb = new DatabaseParameterBuffer();

- dpb.Append(IscCodes.isc_dpb_version1);
+ dpb.Append(IscCodes.isc_dpb_version2);
dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });
dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });
if (!string.IsNullOrEmpty(options.UserID))
diff --git a/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs b/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs
index e4890dcd..cec4413d 100644
--- a/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs
+++ b/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs
@@ -402,7 +402,7 @@ namespace FirebirdSql.Data.FirebirdClient
{
var dpb = new DatabaseParameterBuffer();

- dpb.Append(IscCodes.isc_dpb_version1);
+ dpb.Append(IscCodes.isc_dpb_version2);
dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });
dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });
dpb.Append(IscCodes.isc_dpb_lc_ctype, options.Charset);

=>

Expected behaviour: .NET provider supports connections with Windows Trusted User authentication.

Actual behaviour: Windows Trusted User authentication connection fails with "Invalid clumplet buffer structure: buffer end before end of clumplet - clumplet too long".

Steps to reproduce:

PS C:\temp> Add-Type -Path FirebirdSql.Data.FirebirdClient.7.5.0.dll
>> $factory = [FirebirdSql.Data.FirebirdClient.FirebirdClientFactory]::Instance
>> $conn = $factory.CreateConnection()
>> $conn.ConnectionString = "Server=dvpapainca01;Port=3051;Database=incastatus;"
>> $conn.Open()
Exception calling "Open" with "0" argument(s): "Invalid clumplet buffer structure: buffer end before end of clumplet - clumplet too long"
At line:5 char:1
+ $conn.Open()
+ ~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FbException

Description:

This appears to be a result of win_sspi auth info overflowing the isc_dpb_version1 block - presumably there is an element to this specific to the Windows domain?
By changing to isc_dpb_version2, the connection succeeds. I've attached a diff for this change below, but it's a naive solution - presumably there would be backwards compatibility issues with a straight switch.

PS C:\temp> Add-Type -Path FirebirdSql.Data.FirebirdClient.7.5.0+isc_dpb_version2.dll
>> $factory = [FirebirdSql.Data.FirebirdClient.FirebirdClientFactory]::Instance
>> $conn = $factory.CreateConnection()
>> $conn.ConnectionString = "Server=dvpapainca01;Port=3051;Database=incastatus;"
>> $conn.Open()

PS C:\temp> $conn
ConnectionString : Server=dvpapainca01;Port=3051;Database=incastatus;
ConnectionTimeout : 15
Database : incastatus
DataSource : dvpapainca01
ServerVersion : WI-V3.0.5.33220 Firebird 3.0/tcp (DVPAPAINCA01)/P13
State : Open
PacketSize : 8192
Site :
Container :

diff --git a/Provider/src/FirebirdSql.Data.FirebirdClient/Common/DatabaseParameterBuffer.cs b/Provider/src/FirebirdSql.Data.FirebirdClient/Common/DatabaseParameterBuffer.cs
index 4f10ee72..aa851e6e 100644
--- a/Provider/src/FirebirdSql.Data.FirebirdClient/Common/DatabaseParameterBuffer.cs
+++ b/Provider/src/FirebirdSql.Data.FirebirdClient/Common/DatabaseParameterBuffer.cs
@@ -31,21 +31,21 @@ namespace FirebirdSql.Data.Common
public void Append(int type, byte value)
{
WriteByte(type);
- WriteByte(1);
+ Write((int)1);
Write(value);
}

	public void Append\(int type, short value\)
	\{
		WriteByte\(type\);

- WriteByte(2);
+ Write((int)2);
Write(value);
}

	public void Append\(int type, int value\)
	\{
		WriteByte\(type\);

- WriteByte((byte)4);
+ Write((int)4);
Write(value);
}

@@ -57,7 +57,7 @@ namespace FirebirdSql.Data.Common
public void Append(int type, byte[] buffer)
{
WriteByte(type);
- WriteByte(buffer.Length);
+ Write((int)buffer.Length);
Write(buffer);
}
}
diff --git a/Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs b/Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs
index 65c5b4e7..76a0cf0a 100644
--- a/Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs
+++ b/Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs
@@ -224,6 +224,7 @@ namespace FirebirdSql.Data.Common
#⁠region Database Parameter Block

	public const int isc\_dpb\_version1 = 1;

+ public const int isc_dpb_version2 = 2; // sjd: support >256-byte entries - requires FB3 / protocol 13
public const int isc_dpb_cdd_pathname = 1;
public const int isc_dpb_allocation = 2;
public const int isc_dpb_journal = 3;
diff --git a/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs b/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs
index f6d38a65..aa79ab62 100644
--- a/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs
+++ b/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs
@@ -73,7 +73,7 @@ namespace FirebirdSql.Data.FirebirdClient
{
var dpb = new DatabaseParameterBuffer();

- dpb.Append(IscCodes.isc_dpb_version1);
+ dpb.Append(IscCodes.isc_dpb_version2);
dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });
dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });
if (!string.IsNullOrEmpty(options.UserID))
diff --git a/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs b/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs
index e4890dcd..cec4413d 100644
--- a/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs
+++ b/Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionInternal.cs
@@ -402,7 +402,7 @@ namespace FirebirdSql.Data.FirebirdClient
{
var dpb = new DatabaseParameterBuffer();

- dpb.Append(IscCodes.isc_dpb_version1);
+ dpb.Append(IscCodes.isc_dpb_version2);
dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });
dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });
dpb.Append(IscCodes.isc_dpb_lc_ctype, options.Charset);

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue is related to DNET941 [ DNET941 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue is duplicated by DNET941 [ DNET941 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => In Progress [ 3 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue is related to DNET941 [ DNET941 ] =>

@firebird-automations
Copy link
Author

Commented by: @cincuranet

The issue should be fixed now (at least in my environment it is) in this (https://teamcity.jetbrains.com/viewLog.html?buildId=3099959&buildTypeId=OpenSourceProjects_FirebirdClient_CiBuildItems_ProviderCoreFb30&tab=artifacts) build. Can somebody test it and confirm?

@firebird-automations
Copy link
Author

@firebird-automations
Copy link
Author

Commented by: @cincuranet

Thanks for confirmation. It will be in next release (1-2 months).

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: In Progress [ 3 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: vNext [ 10920 ]

@firebird-automations
Copy link
Author

Commented by: @luronumen

Thank you very much Jiri Cincura!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants