lstrcpy function

 

Warning  Do not use. Consider using StringCchCopy instead. See Remarks.

Syntax

LPTSTR WINAPI lstrcpy(
  __out  LPTSTR lpString1,
  __in   LPTSTR lpString2
);

Parameters

lpString1 [out]

Type: LPTSTR

A buffer to receive the contents of the string pointed to by the lpString2 parameter. The buffer must be large enough to contain the string, including the terminating null character.

lpString2 [in]

Type: LPTSTR

The null-terminated string to be copied.

Return value

Type: LPTSTR

If the function succeeds, the return value is a pointer to the buffer.

If the function fails, the return value is NULL and lpString1 may not be null-terminated.

Remarks

With a double-byte character set (DBCS) version of the system, this function can be used to copy a DBCS string.

The lstrcpy function has an undefined behavior if source and destination buffers overlap.

Security Remarks

Using this function incorrectly can compromise the security of your application. This function uses structured exception handling (SEH) to catch access violations and other errors. When this function catches SEH errors, it returns NULL without null-terminating the string and without notifying the caller of the error. The caller is not safe to assume that insufficient space is the error condition.

lpString1 must be large enough to hold lpString2 and the closing '\0', otherwise a buffer overrun may occur.

Buffer overflow situations are the cause of many security problems in applications and can cause a denial of service attack against the application if an access violation occurs. In the worst case, a buffer overrun may allow an attacker to inject executable code into your process, especially if lpString1 is a stack-based buffer.

Consider using StringCchCopy instead; use either StringCchCopy(buffer, sizeof(buffer)/sizeof(buffer[0]), src);, being aware that buffer must not be a pointer or use StringCchCopy(buffer, ARRAYSIZE(buffer), src);, being aware that, when copying to a pointer, the caller is responsible for passing in the size of the pointed-to memory in characters.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值