Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 09-01-2004, 15:38
adkiller
 
Posts: n/a
strcpy in MT apps leaks memory?

I was at an interview last friday for a CPP job.

The guy conducting the interview asked me how proficient I was with MSVC. He then later asked me about what problems are there when using strcpy in a MT (Multi-Threaded) app?

I said none, it can be used as nomal. He said no, strcpy produces memory leaks when used in a MT app and he claimed that MS recommends using the Win32 API StrCpy instead of the STDC strcpy function. He said MS did this on purpose to force devs to use the Win32 equivalent.

Is this true for MSVC6? Is there any way for me to verify this accurately in MSVC 7.1?
Reply With Quote
  #2  
Old 09-01-2004, 20:46
TQN TQN is offline
VIP
 
Join Date: Apr 2003
Location: Vietnam
Posts: 343
Rept. Given: 142
Rept. Rcvd 20 Times in 12 Posts
Thanks Given: 169
Thanks Rcvd at 130 Times in 43 Posts
TQN Reputation: 20
No, he wrong 100%. strcpy and StrCpy (in ShlWApi.dll) did not have any problems in Multithread or Single Thread mode. They are only a rep movsd or rep stosd, and do not allocate or free any memory. It is same for RtlMoveMemory in NTDLL.dll. You can view the source code of strcpy in your VC crt\src folder.
TQN
Reply With Quote
  #3  
Old 09-01-2004, 23:45
JMI JMI is offline
Leader
 
Join Date: Jan 2002
Posts: 1,627
Rept. Given: 5
Rept. Rcvd 199 Times in 99 Posts
Thanks Given: 0
Thanks Rcvd at 96 Times in 94 Posts
JMI Reputation: 100-199 JMI Reputation: 100-199
Then it would appear that it was the interviewer's memory which was "leaking."

Regards,
__________________
JMI
Reply With Quote
  #4  
Old 09-01-2004, 23:59
lifewire
 
Posts: n/a
the StrCpyW i have in shlwapi.dll is indeed a very simple memory copy until 0 (not really a rep movsd as said above, but something like it). and actually, i can't imagine a way why a memoryleak would ever occur in such a function. strange hoax, imho.
Reply With Quote
  #5  
Old 09-02-2004, 02:44
Sergey Nameless
 
Posts: n/a
This is what MS says about StrCpy:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/shlwapi/string/strcpy.asp

Security Alert Using this function incorrectly can compromise the security of your application. The first argument, psz1, must be large enough to hold psz2 and the closing '\0', otherwise a buffer overrun may occur. Buffer overruns may lead to 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 psz1 is a stack-based buffer. Consider using one of the following alternatives: StringCbCopy, StringCbCopyEx, StringCbCopyN, StringCbCopyNEx, StringCchCopy, StringCchCopyEx, StringCchCopyN, or StringCchCopyNEx. You should review Security Considerations: Microsoft Windows Shell before continuing.
Reply With Quote
  #6  
Old 09-02-2004, 03:15
Perdition
 
Posts: n/a
In my opinion it's a retarded question for an interview anyway and you're probably better off not working for them. They should rather test your skill at coding than ask superfluous questions. I reckon the interviewer just has a big ego and his head stuck up his ass
Reply With Quote
  #7  
Old 09-02-2004, 04:06
lifewire
 
Posts: n/a
also his "conspiracy theory" that it would have been done to force people use the api version shows that you are better off if you didn't get the job
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Armadilled apps Annibal General Discussion 12 02-10-2005 23:29


All times are GMT +8. The time now is 10:38.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )