[Spice-devel] [vdagent-win 3/3] Remove MSVC++ strncpy/strcat fallbacks

Christophe Fergeau cfergeau at redhat.com
Fri Mar 20 02:34:48 PDT 2015


On Thu, Mar 19, 2015 at 01:50:38PM +0200, Uri Lublin wrote:
> On 02/16/2015 12:29 PM, Christophe Fergeau wrote:
> >We currently have macros silently replacing use of strncpy/strcat with
> >strcpy_s/strcat_s when using MSVC++. However, these macros can have
> >unexpected effects as they use sizeof to find out the maximum size of
> >the destination string. This is a very significant behaviour from
> >strncpy/strcat, which can lead to subtle bugs as the behaviour is
> >different between mingw and MSVC++.
> >Now that we have our implementation of strcpy_s/strcat_s, we don't need
> >these #defines.
> 
> I think this patch can be squashed into the previous
> patch, which makes use of vdagent_str*_s and making
> these macros unused. I'm fine with leaving it as is.

I have a slight preference for keeping a separate commit, so I'll leave
things this way.

> 
> >---
> >  common/vdcommon.h   | 2 --
> >  vdagent/file_xfer.h | 2 +-
> >  2 files changed, 1 insertion(+), 3 deletions(-)
> >
> >diff --git a/common/vdcommon.h b/common/vdcommon.h
> >index 002ac23..93bb673 100644
> >--- a/common/vdcommon.h
> >+++ b/common/vdcommon.h
> >@@ -92,8 +92,6 @@ errno_t vdagent_strcpy_s(char *strDestination,
> >
> >  #ifdef _MSC_VER // compiling with Visual Studio
> >  #define snprintf         sprintf_s
> >-#define strncpy(d,s,n)   strcpy_s(s, __min(n+1, sizeof(d)), s)
> >-#define strcat(d,s)      strcat_s(d, sizeof(d), s)
> >  #define sscanf           sscanf_s
> >  #endif
> >
> >diff --git a/vdagent/file_xfer.h b/vdagent/file_xfer.h
> >index 7f756e3..7ac911e 100644
> >--- a/vdagent/file_xfer.h
> >+++ b/vdagent/file_xfer.h
> >@@ -27,7 +27,7 @@ typedef struct ALIGN_VC FileXferTask {
> >          // FIXME: should raise an error if name is too long..
> >          //        currently the only user is FileXfer::handle_start
> >          //        which verifies that strlen(_name) < MAX_PATH
> >-        vdagent_strncpy_s(name, sizeof(name), _name);
> >+        vdagent_strcpy_s(name, sizeof(name), _name);
> 
> This is to be squashed in the previous patch
> 


Yup, messed up rebase/split, thanks for catching. I've fixed that
locally.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20150320/635e0e29/attachment.sig>


More information about the Spice-devel mailing list