Re: [vdagent-win V2 4/6] Fix Visual Studio compiler warning (sscanf/strcat)

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

 



Hey,

Finally received 4/6 ;)

On Mon, Mar 24, 2014 at 07:02:41PM +0200, Uri Lublin wrote:
> This commit partially reverts 4b9e9b1d28ea7eaec44ff73e2f91c4064986b12a.
> 
> Visual Studio complains about non-safe sscanf and strcat:
>     vdagent\file_xfer.cpp(89) : warning C4996: 'strcat': This function
>     or variable may be unsafe.  Consider using strcat_s instead.
>     To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
>     See online help for details.
> 
> Replace them with sscanf_s and strcat_s.
> Add #define macros when building with mingw.
> Note that for strcat_s, size parameter (NumberOfElements) represents the
> size of destination-buffer, while for strncat, size parameter (n)
> represents the number of characters to copy.
> ---
>  vdagent/file_xfer.cpp | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
> index 01072ba..3bed1b1 100644
> --- a/vdagent/file_xfer.cpp
> +++ b/vdagent/file_xfer.cpp
> @@ -24,6 +24,8 @@
>  #define PRIu64 "I64u"
>  #else // compiling with mingw
>  #include <inttypes.h>
> +#define sscanf_s sscanf
> +#define strcat_s(d, n, s) strncat(d, s, n - strlen(d))

It turns out the mingw version on my system (fedora 20) has strcat_s, and
should have sscanf_s, so I suggest to turn this into configure.ac checks:

AC_CHECK_FUNCS([strcat_s strncpy_s sscanf_s])

combined with

diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
index e402eb2..a71000f 100644
--- a/vdagent/file_xfer.cpp
+++ b/vdagent/file_xfer.cpp
@@ -15,6 +15,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <shlobj.h>
 #define __STDC_FORMAT_MACROS
 #define __USE_MINGW_ANSI_STDIO 1
@@ -23,6 +26,14 @@
 #include "file_xfer.h"
 #include "as_user.h"

+#ifndef HAVE_SSCANF_S
+// sscanf_s fallback
+#endif
+
+#ifndef HAVE_STRCAT_S
+// strcat_s fallback
+#endif
+

One bit I did not get right yet is that a standalone test program and the
AC_CHECK_FUNCS() call can successfully use sscanf_s, but trying to use it
in file-xfer.c results in a compilation failure, not quite sure about the
difference :(

Christophe

Attachment: pgpYOUGXcY_bD.pgp
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]