qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 4/5] libcacard: replace qemu thread primitives w


From: Michael Tokarev
Subject: Re: [Qemu-devel] [PATCH 4/5] libcacard: replace qemu thread primitives with glib ones
Date: Tue, 29 Apr 2014 20:18:46 +0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.4.0

29.04.2014 13:11, Paolo Bonzini wrote:
> Il 29/04/2014 10:42, Michael Tokarev ha scritto:
>>>>>> >>> > Also replace single instance pstrcpy() in vcard_emul_nss.c
>>>>>> >>> > to strncpy().  This reverts commit 2e679780ae86c6ca8.
>>>> >> An alternative would be to use g_strlcpy which guarantees
>>>> >> nul-termination.
>>> >
>>> > Yes, that is better.
>> Actually in this very place it isn't really important, given we
>> always know the exact length of the source and are able to adjust
>> it to fit into the buffer.  With g_strlcat() code becomes a bit
>> more ugly... ;)
> 
> Uh, now I looked at NEXT_TOKEN and g_strlcpy suddenly becomes less palatable. 
>  mempcpy would be nice actually, like
> 
>     *mempcpy(dest, src, type_params_length) = 0;

I just pushed a new series for this, with this change being in
a separate commit.  See there:

 http://git.corpit.ru/?p=qemu.git;a=shortlog;h=refs/heads/libcacard-standalone

As promised, I've split this change into a sepatate patch, this:

Author: Michael Tokarev <address@hidden>
Date:   Tue Apr 29 20:10:48 2014 +0400

    libcacard: replace pstrcpy() with memcpy()

    Commit 2e679780ae86c6ca8 replaced strncpy() with pstrcpy()
    in one place in libcacard.  This is a qemu-specific function,
    while libcacard is a stand-alone library (or tries to be).
    But since we know the exact length of the string to copy,
    and know that it definitely will fit in the destination
    buffer, use memcpy() instead, and null-terminate the string
    after that.

    An alternative is to use g_strlcpy() or strncpy(), but memcpy()
    is more than adequate in this place.

    Signed-off-by: Michael Tokarev <address@hidden>

diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index ee2dfae..e2b196d 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -1162,7 +1162,8 @@ vcard_emul_options(const char *args)
             NEXT_TOKEN(vname)
             NEXT_TOKEN(type_params)
             type_params_length = MIN(type_params_length, sizeof(type_str)-1);
-            pstrcpy(type_str, type_params_length, type_params);
+            memcpy(type_str, type_params, type_params_length);
+            type_str[type_params_length] = '\0';
             type = vcard_emul_type_from_string(type_str);

             NEXT_TOKEN(type_params)

I also fixed the commit message about vscclient sptted by
Christophe.

Thanks,

/mjt



reply via email to

[Prev in Thread] Current Thread [Next in Thread]