Modify

Opened 18 years ago

Closed 18 years ago

#92 closed Bug (Fixed)

DllStructGetData() truncation

Reported by: Valik Owned by: Valik
Milestone: 3.2.13.8 Component: AutoIt
Version: 3.2.10.0 Severity: None
Keywords: Cc:

Description

DllStructGetData() truncates the last element of a (char/wchar) array to ensure null termination. The code needs modified to secretly allocate a larger buffer and secretly insert a null terminator outside the user-requested bounds so the user's data is not altered.

This is a display-only issue, the underlying data is not changed.

Attachments (1)

DllStructTrunc.au3 (263 bytes ) - added by Valik 18 years ago.

Download all attachments as: .zip

Change History (14)

by Valik, 18 years ago

Attachment: DllStructTrunc.au3 added

comment:1 by Jon, 18 years ago

Owner: set to Jon
Status: newaccepted

I'll sort this when I rewrite DllStruct.

in reply to:  description ; comment:2 by J-Paul Mesnage, 18 years ago

Replying to Valik:

DllStructGetData() truncates the last element of a (char/wchar) array to ensure null termination. The code needs modified to secretly allocate a larger buffer and secretly insert a null terminator outside the user-requested bounds so the user's data is not altered.

This is a display-only issue, the underlying data is not changed.

This will have drawback when the user use DllStructGetptr to access inner structure.
Scripter should respect the +1 if needed and only DllStructSetData will be protected against the overflow as DllCall using this struct can always overflow

in reply to:  2 ; comment:3 by Valik, 18 years ago

Replying to Jpm:

This will have drawback when the user use DllStructGetptr to access inner structure.
Scripter should respect the +1 if needed and only DllStructSetData will be protected against the overflow as DllCall using this struct can always overflow

There is no drawback to allocating a larger buffer than requested. Once this ticket is closed and the thread where it was discovered fades away, user's won't even know that we allocate a larger buffer than they request. If your concern is a 1- or 2-byte buffer overflow won't be detected, then we can change the extra out-of-user-area bytes to read-only and trap any exception that occurs.

in reply to:  3 ; comment:4 by Valik, 18 years ago

... then we can change the extra out-of-user-area bytes to read-only and trap any exception that occurs.

Oh, and we should probably be doing this anyway. I suggested it once. It's a really easy way to catch buffer overflows with DllStruct stuff, so if we are going to allocate larger blocks for "house-keeping" data we should go ahead and mark it read-only and detect an attempts to write to it.

in reply to:  4 comment:5 by J-Paul Mesnage, 18 years ago

Replying to Valik:

... then we can change the extra out-of-user-area bytes to read-only and trap any exception that occurs.

Oh, and we should probably be doing this anyway. I suggested it once. It's a really easy way to catch buffer overflows with DllStruct stuff, so if we are going to allocate larger blocks for "house-keeping" data we should go ahead and mark it read-only and detect an attempts to write to it.

I don't understand how we can catch buffer overflow when dllstruct use by a DllCall that can set beyound whatever is hidden allocated

comment:6 by Valik, 18 years ago

Severity: None

Jon, is this fixed in your DllStruct implementation rewrite?

comment:7 by Jon, 18 years ago

No. I looked at it briefly, decided it was right as it was and then changed my mind, got confused and ignored it.

comment:8 by Valik, 18 years ago

Jon, the current behavior is wrong and causes data-loss of 1 character every time a string is read when strlen() == sizeof(buffer). For example, BSTR's don't have null terminators, they store the size in the first WORD (or something like that). Attempting to use this with an exact-sized BSTR-style string would cause data-loss of the last character.

AutoIt is assuming all array's are sized to correctly hold a null terminator and that it's okay to replace the last character with a null terminator when reading. This assumption is wrong since we don't know enough about how the data is being used to make that assumption.

comment:9 by Valik, 18 years ago

Milestone: 3.2.13.6
Owner: changed from Jon to Valik
Resolution: Fixed
Status: acceptedclosed

Fixed in version: 3.2.13.6

comment:10 by Valik, 18 years ago

Milestone: 3.2.13.6
Resolution: Fixed
Severity: NoneBlocking
Status: closedreopened

Re-opening because I didn't fix this correctly the first time around. Also setting as blocking because I kind of made things worse.

comment:11 by Valik, 18 years ago

Status: reopenedaccepted

comment:12 by Valik, 18 years ago

Severity: BlockingNone

comment:13 by Valik, 18 years ago

Milestone: 3.2.13.8
Resolution: Fixed
Status: acceptedclosed

Fixed in version: 3.2.13.8

Modify Ticket

Action
as closed The owner will remain Valik.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.