Re: [PATCH] shell32: replace strcpy by memcpy due to slightly undefined struct handling
- strcpy(pData->u.network.szNames, "Entire Network"); + memcpy(pData->u.network.szNames, "Entire Network", sizeof("Entire Network")+1);
Please use a const buffer as "Entire Network" is a string literal, not something with a clearly defined size (not even talking about length). const char entireNetwork[] = "Entire Network"; ... memcpy(pData->u.network.szNames, entireNetwork, sizeof(entireNetwork)); The final NUL is part of the char array. Regardless, we may still copy some garbage after the NUL depending if/how the compiler pads the buffer. Probably a better way would be to simply cast (char*)pData->u.network.szNames since the length is not checked anyway. Regards, Paul
On Mon, Feb 15, 2010 at 06:46:06PM +0200, Paul Chitescu wrote:
- strcpy(pData->u.network.szNames, "Entire Network"); + memcpy(pData->u.network.szNames, "Entire Network", sizeof("Entire Network")+1);
Please use a const buffer as "Entire Network" is a string literal, not something with a clearly defined size (not even talking about length).
const char entireNetwork[] = "Entire Network"; ... memcpy(pData->u.network.szNames, entireNetwork, sizeof(entireNetwork));
The final NUL is part of the char array. Regardless, we may still copy some garbage after the NUL depending if/how the compiler pads the buffer.
Probably a better way would be to simply cast (char*)pData->u.network.szNames since the length is not checked anyway.
The compiler checks the target size, and (char*) will not hinder the compiler to check it. I did not really want to uglify this code more then necessary. :( Ciao, Marcus
participants (2)
-
Marcus Meissner -
Paul Chitescu