Wrong implementation of strncpy

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
rothfussthomas
Jr. Member
Jr. Member
Posts: 3
Joined: 11 Jan 2012, 11:24

Wrong implementation of strncpy

Post by rothfussthomas »

Hi,

there's following example code running under Windows:

UaDateTime date_time;
UaString s;
s = date_time.toString ();

Therefore dwLowDateTime and dwHighDateTime are 0.
Within ...uastackplatformswin32_v6opcua_p_datetime.c following function is called:

OpcUa_P_String_strncpy(a_pBuffer, a_uLength, OPCUA_P_DATETIME_EARLIEST, (OpcUa_UInt32)strlen(OPCUA_P_DATETIME_EARLIEST));

Within ...uastackplatformswin32_v6opcua_p_string.c the function OpcUa_P_String_strncpy is called and then

if(strncpy(a_strDestination, a_strSource, a_uiLength) != a_strDestination)

a_uiLength is 24. This means that there's no trailing '0' inserted since a_uiLength is equal to the length of the string. The description of strncpy of the Microsoft Help says: "If count is greater than the length of strSource, the destination string is padded with null characters up to length count."

a_uiLength should be replaced by a_uiDestSize

Best Regards,
Thomas

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re:Wrong implementation of strncpy

Post by Support Team »

Hi Thomas,

Thank you for reporting this issue.

This is a known issue that was already fixed. The fix will be contained in the next service release 1.3.2 we are currently working on.

Please contact support@unifiedautomation.com if you need this single patch earlier.

Best Regards,
Unified Automation Support Team
Best regards
Unified Automation Support Team

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re:Wrong implementation of strncpy

Post by Support Team »

Hi,

The new service release for the C++ SDK (V1.3.2) is now available for download

http://www.unified-automation.com/opc-ua-servers/

Best Regards,
Unified Automation Support Team
Best regards
Unified Automation Support Team

Post Reply