From 65884f4d9e619fc797e273a338e2391442cca9f6 Mon Sep 17 00:00:00 2001 From: topilski Date: Sun, 30 Jul 2017 07:30:05 +0300 Subject: [PATCH 1/8] Fix parsing doubles for mingw --- json_util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/json_util.c b/json_util.c index 3a717b7..cc57e34 100644 --- a/json_util.c +++ b/json_util.c @@ -195,7 +195,9 @@ int json_object_to_file(const char *filename, struct json_object *obj) int json_parse_double(const char *buf, double *retval) { - return (sscanf(buf, "%lf", retval)==1 ? 0 : 1); + char *end; + *retval = strtod(buf, &end); + return end == buf ? 1 : 0; } /* From 0a99e7a5c1b1ec576a516485bbd96b0a116c6825 Mon Sep 17 00:00:00 2001 From: topilski Date: Sun, 30 Jul 2017 07:37:17 +0300 Subject: [PATCH 2/8] Fix Mingw build --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24ddac5..bf6929f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,7 @@ set(JSON_C_SOURCES ./linkhash.c ./printbuf.c ./random_seed.c + ./strerror_override.c ) add_library(json-c From db8dbbf3719bd479adc12481dc540b88be9e6255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20V=C3=A1rady?= Date: Fri, 4 Aug 2017 11:59:14 +0200 Subject: [PATCH 3/8] Fix 'make dist' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EXTRA_DIST copies the listed directories/files from the _source_ directory into the distribution. Since the doc directory does not exist after running autogen + configure + make dist, the distribution tarball generation fails. Note that the dist-hook rule below operates on 'distdir', not on the source directory where EXTRA_DIST expects the existence of the doc folder. In summary, even if I removed 'doc' from EXTRA_DIST, the dist tarball will always contain the documentation (due to the dist-hook rule). Signed-off-by: László Várady --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 8728ff0..cce39a0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ EXTRA_DIST = README.md README.html README-WIN32.html EXTRA_DIST += config.h.win32 json-c.vcproj json-c.vcxproj json-c.vcxproj.filters -EXTRA_DIST += Doxyfile doc +EXTRA_DIST += Doxyfile dist-hook: test -d "$(distdir)/doc" || mkdir "$(distdir)/doc" From e0e34f0a13c581d0e7527a2ce7dcb9cc8b6e403f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20V=C3=A1rady?= Date: Fri, 4 Aug 2017 12:26:54 +0200 Subject: [PATCH 4/8] Fix 'make distcheck' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: László Várady --- Makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index cce39a0..bb4fb6a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,7 +35,8 @@ libjson_cinclude_HEADERS = \ strdup_compat.h \ vasprintf_compat.h \ printbuf.h \ - random_seed.h + random_seed.h \ + strerror_override.h libjson_c_la_LDFLAGS = -version-info 3:0:0 -no-undefined @JSON_BSYMBOLIC_LDFLAGS@ @@ -52,7 +53,8 @@ libjson_c_la_SOURCES = \ linkhash.c \ printbuf.c \ random_seed.c \ - strerror_override.c + strerror_override.c \ + strerror_override_private.h distclean-local: -rm -rf $(testsubdir) From ef7b08ce7f53aeebc1313c214a2ac1e860dbb309 Mon Sep 17 00:00:00 2001 From: Kurt Schwehr Date: Tue, 8 Aug 2017 07:54:38 -0700 Subject: [PATCH 5/8] Clamp double to int32 when narrowing in json_object_get_int. Avoids undefined behavior. Found by autofuzz. --- json_object.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/json_object.c b/json_object.c index 8c80426..7148731 100644 --- a/json_object.c +++ b/json_object.c @@ -635,6 +635,10 @@ int32_t json_object_get_int(const struct json_object *jso) return INT32_MAX; return (int32_t) cint64; case json_type_double: + if (jso->o.c_double <= INT32_MIN) + return INT32_MIN; + if (jso->o.c_double >= INT32_MAX) + return INT32_MAX; return (int32_t)jso->o.c_double; case json_type_boolean: return jso->o.c_boolean; From 81f6edbfd579214b3e337885b5148c3931780365 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Fri, 25 Aug 2017 01:15:39 -0400 Subject: [PATCH 6/8] PR#331: for Visual Studio, use a snprintf/vsnprintf wrapper that ensures the string is terminated. --- json_object.c | 8 +------- json_util.c | 7 +------ printbuf.c | 1 + snprintf_compat.h | 36 ++++++++++++++++++++++++++++++++++++ tests/test_locale.c | 1 + vasprintf_compat.h | 6 +----- 6 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 snprintf_compat.h diff --git a/json_object.c b/json_object.c index 7148731..a317123 100644 --- a/json_object.c +++ b/json_object.c @@ -31,13 +31,7 @@ #include "json_util.h" #include "math_compat.h" #include "strdup_compat.h" - -#if !defined(HAVE_SNPRINTF) && defined(_MSC_VER) - /* MSC has the version as _snprintf */ -# define snprintf _snprintf -#elif !defined(HAVE_SNPRINTF) -# error You do not have snprintf on your system. -#endif /* HAVE_SNPRINTF */ +#include "snprintf_compat.h" // Don't define this. It's not thread-safe. /* #define REFCOUNT_DEBUG 1 */ diff --git a/json_util.c b/json_util.c index cc57e34..2121150 100644 --- a/json_util.c +++ b/json_util.c @@ -48,12 +48,7 @@ # define open _open #endif -#if !defined(HAVE_SNPRINTF) && defined(_MSC_VER) - /* MSC has the version as _snprintf */ -# define snprintf _snprintf -#elif !defined(HAVE_SNPRINTF) -# error You do not have snprintf on your system. -#endif /* HAVE_SNPRINTF */ +#include "snprintf_compat.h" #include "debug.h" #include "printbuf.h" diff --git a/printbuf.c b/printbuf.c index 2745339..6c77b5d 100644 --- a/printbuf.c +++ b/printbuf.c @@ -27,6 +27,7 @@ #include "debug.h" #include "printbuf.h" +#include "snprintf_compat.h" #include "vasprintf_compat.h" static int printbuf_extend(struct printbuf *p, int min_size); diff --git a/snprintf_compat.h b/snprintf_compat.h new file mode 100644 index 0000000..7323aaa --- /dev/null +++ b/snprintf_compat.h @@ -0,0 +1,36 @@ +#ifndef __snprintf_compat_h +#define __snprintf_compat_h + +/* + * Microsoft's _vsnprintf and _snprint don't always terminate + * the string, so use wrappers that ensure that. + */ + +#include + +#if !defined(HAVE_SNPRINTF) && defined(_MSC_VER) +static int json_c_vsnprintf(char *str, size_t size, const char *format, va_list ap) +{ + int ret; + ret = _vsnprintf(str, size, format, ap); + str[size - 1] = '\0'; + return ret; +} +#define vsnprintf json_c_vsnprintf + +static int json_c_snprintf(char *str, size_t size, const char *format, ...) +{ + va_list ap; + int ret; + va_start(ap, format); + ret = json_c_vsnprintf(str, size, format, ap); + va_end(ap); + return ret; +} +#define snprintf json_c_snprintf + +#elif !defined(HAVE_SNPRINTF) /* !HAVE_SNPRINTF */ +# error Need vsnprintf! +#endif /* !HAVE_SNPRINTF && defined(WIN32) */ + +#endif /* __snprintf_compat_h */ diff --git a/tests/test_locale.c b/tests/test_locale.c index a3e319d..7d6541a 100644 --- a/tests/test_locale.c +++ b/tests/test_locale.c @@ -7,6 +7,7 @@ #include "config.h" #include "json.h" #include "json_tokener.h" +#include "snprintf_compat.h" #ifdef HAVE_LOCALE_H #include diff --git a/vasprintf_compat.h b/vasprintf_compat.h index 51e234b..40ff550 100644 --- a/vasprintf_compat.h +++ b/vasprintf_compat.h @@ -1,11 +1,7 @@ #ifndef __vasprintf_compat_h #define __vasprintf_compat_h -#if !defined(HAVE_VSNPRINTF) && defined(_MSC_VER) -# define vsnprintf _vsnprintf -#elif !defined(HAVE_VSNPRINTF) /* !HAVE_VSNPRINTF */ -# error Need vsnprintf! -#endif /* !HAVE_VSNPRINTF && defined(WIN32) */ +#include "snprintf_compat.h" #if !defined(HAVE_VASPRINTF) /* CAW: compliant version of vasprintf */ From 447d67d5f310d7275e3113475099bfcb0b184824 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Wed, 30 Aug 2017 23:17:24 -0400 Subject: [PATCH 7/8] Issue #349: none of automake's clean targets are suite for really cleaning up everything, so add a local "really-clean" target that does so. --- Makefile.am | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index bb4fb6a..cd32b4c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,13 +56,43 @@ libjson_c_la_SOURCES = \ strerror_override.c \ strerror_override_private.h + +DISTCLEANFILES= +DISTCLEANFILES+= \ + config.h \ + json-c-uninstalled.pc \ + json-c.pc \ + json_config.h + distclean-local: -rm -rf $(testsubdir) - -rm -rf config.h.in~ Makefile.in aclocal.m4 autom4te.cache/ config.guess config.sub depcomp install-sh ltmain.sh missing - -rm -f INSTALL test-driver tests/Makefile.in compile -maintainer-clean-local: - -rm -rf configure +JSON_CLEANFILES= +JSON_CLEANFILES+= \ + Makefile.in \ + aclocal.m4 \ + autom4te.cache/ \ + compile \ + config.guess \ + config.h.in \ + config.sub \ + configure \ + depcomp \ + install-sh \ + ltmain.sh \ + missing \ + test-driver \ + tests/Makefile.in +JSON_CLEANFILES+= \ + libtool \ + stamp-h1 \ + stamp-h2 + +# There's no built-in way to remove these after all the other +# maintainer-clean steps happen, so do it explicitly here. +really-clean: + $(MAKE) maintainer-clean + rm -rf ${JSON_CLEANFILES} uninstall-local: rm -rf "$(DESTDIR)@includedir@/json-c" From 95dff31951c9388408d29e7ddf9a9edc4ec96dca Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Wed, 30 Aug 2017 23:35:56 -0400 Subject: [PATCH 8/8] Issue #351: don't redefine SIZE_T_MAX if it's already defined. --- arraylist.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arraylist.c b/arraylist.c index 8439cc2..ddeb8d4 100644 --- a/arraylist.c +++ b/arraylist.c @@ -22,6 +22,7 @@ # include #endif /* HAVE_STRINGS_H */ +#ifndef SIZE_T_MAX #if SIZEOF_SIZE_T == SIZEOF_INT #define SIZE_T_MAX UINT_MAX #elif SIZEOF_SIZE_T == SIZEOF_LONG @@ -31,6 +32,7 @@ #else #error Unable to determine size of size_t #endif +#endif #include "arraylist.h"