If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

windows _snprintf() may not work like VMPI_snprintf expects it to

VERIFIED FIXED in flash10.1

Status

Tamarin
Virtual Machine
P2
normal
VERIFIED FIXED
8 years ago
8 years ago

People

(Reporter: Edwin Smith, Assigned: Lars T Hansen)

Tracking

unspecified
flash10.1
x86
Windows XP

Details

(Whiteboard: Has patch)

Attachments

(1 attachment, 3 obsolete attachments)

(Reporter)

Description

8 years ago
From Nicholas Nethercote nanojit developer:

I just learnt the hard way that snprintf() doesn't exist on Windows.
There is _snprintf(), but it's unsafe -- it doesn't guarantee
terminating with a NUL char.  sprintf_s() is the function that does
that.

http://msdn.microsoft.com/en-us/library/2ts7cx93%28VS.80%29.aspx
http://msdn.microsoft.com/en-us/library/ce3zzk1k%28VS.80%29.aspx

I mention it because I see the following lines in TR:

./platform/win32/win32-platform.h:#define VMPI_snprintf		::_snprintf
./VMPI/SpyUtilsWin.cpp:	#pragma warning(disable: 4995) //disabling
warning for deprecated _snprintf
./VMPI/SpyUtilsWinMo.cpp:	#pragma warning(disable: 4995) //disabling
warning for deprecated _snprintf
(Assignee)

Updated

8 years ago
Assignee: nobody → lhansen
Priority: -- → P2
Target Milestone: --- → flash10.1
(Assignee)

Comment 1

8 years ago
Right.  The problem is that _snprintf_s does more than just NUL-terminate, it actually invokes an exception handler if the buffer can't accomodate the output.  We probably don't want that.
(Assignee)

Comment 2

8 years ago
Created attachment 433597 [details] [diff] [review]
Patch

Implements VMPI_snprintf and VMPI_vsnprintf as functions on Windows, with reasonable semantics.

Removes the warning-disabling pragmas for _snprintf usage.

Adds VMPI_vsnprintf to all the platform header files (only Windows had it).

Changes some uses in the eval code of non-VMPI functions to use VMPI functions - fallout from removing a use of _snprintf.
Attachment #433597 - Flags: review?(edwsmith)
(Assignee)

Updated

8 years ago
Status: NEW → ASSIGNED
Whiteboard: Has patch
(Reporter)

Updated

8 years ago
Attachment #433597 - Flags: review?(edwsmith) → review+
(Assignee)

Comment 3

8 years ago
A selftest test case would be handy here.
Flags: in-testsuite?
(Assignee)

Comment 4

8 years ago
tamarin-redux-argo changeset:   3846:1bc40e7217a8
tamarin-redux changeset:   4109:0e6e60921250
Status: ASSIGNED → RESOLVED
Last Resolved: 8 years ago
Resolution: --- → FIXED

Comment 5

8 years ago
Looks like this patch does not compile properly on windows mobile:

MMgc/GCLog.cpp(49) : error C3861: 'vsnprintf': identifier not found
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
(Assignee)

Comment 6

8 years ago
(In reply to comment #5)
> Looks like this patch does not compile properly on windows mobile:
> 
> MMgc/GCLog.cpp(49) : error C3861: 'vsnprintf': identifier not found

Bummer for Windows Mobile.
(Assignee)

Updated

8 years ago
Depends on: 554473
(Assignee)

Comment 7

8 years ago
Created attachment 434375 [details] [diff] [review]
Selftests for VMPI_snprintf

These test basic functionality of VMPI_snprintf:

- formatting various types
- handling buffer overflow and termination
- return values

To the best of my knowledge I'm going after only ISO C functionality here.
Attachment #434375 - Flags: review?(edwsmith)
(Assignee)

Comment 8

8 years ago
Created attachment 434377 [details] [diff] [review]
Turn two calls to vsnprintf into calls to VMPI_vsnprintf
Attachment #434377 - Flags: review?(edwsmith)
(Assignee)

Comment 9

8 years ago
Created attachment 434380 [details] [diff] [review]
Reasonably conformant implementation of VMPI_vsnprintf

Performs a rough-and-ready parse of the format string and hands individual problems off to _snprintf, and assembles a string from the results.  Unlike _snprintf and _vsnprintf it returns the number of chars that would have been printed had the buffer been large enough.

Does not quite obsolete patch #433597, but replaces part of it.
Attachment #434380 - Flags: review?(edwsmith)
(Reporter)

Updated

8 years ago
Attachment #434377 - Flags: review?(edwsmith) → review+
(Assignee)

Updated

8 years ago
Depends on: 554659
(Assignee)

Comment 10

8 years ago
Comment on attachment 434377 [details] [diff] [review]
Turn two calls to vsnprintf into calls to VMPI_vsnprintf

Moved to bug #554659.
Attachment #434377 - Attachment is obsolete: true
(Assignee)

Comment 11

8 years ago
Comment on attachment 434375 [details] [diff] [review]
Selftests for VMPI_snprintf

Cancelling review as patch will be moved.
Attachment #434375 - Flags: review?(edwsmith)
(Assignee)

Comment 12

8 years ago
Comment on attachment 434380 [details] [diff] [review]
Reasonably conformant implementation of VMPI_vsnprintf

Cancelling review as patch will be moved.
Attachment #434380 - Flags: review?(edwsmith)
(Assignee)

Updated

8 years ago
No longer depends on: 554473
(Assignee)

Comment 13

8 years ago
Comment on attachment 434375 [details] [diff] [review]
Selftests for VMPI_snprintf

Moved to bug #554664
Attachment #434375 - Attachment is obsolete: true
(Assignee)

Comment 14

8 years ago
Comment on attachment 434380 [details] [diff] [review]
Reasonably conformant implementation of VMPI_vsnprintf

Moved to bug #554664
Attachment #434380 - Attachment is obsolete: true
(Assignee)

Comment 15

8 years ago
(In reply to comment #5)
> Looks like this patch does not compile properly on windows mobile:
> 
> MMgc/GCLog.cpp(49) : error C3861: 'vsnprintf': identifier not found

That issue is now tracked in bug #554659 as it turned out to be more complicated.
Status: REOPENED → RESOLVED
Last Resolved: 8 years ago8 years ago
No longer depends on: 554659
Resolution: --- → FIXED
(Assignee)

Comment 16

8 years ago
Test cases have been moved to bug #554664.
Flags: in-testsuite?

Updated

8 years ago
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.