cJSON
[Ported from github.com/DaveGamble/cJSON] Fix: heap-use-after-free in merge_patch when patch is subtree of target (#1065)
Brought by drakestapleton
cJSON / Makefile
| 1 | CJSON_OBJ = cJSON.o |
| 2 | UTILS_OBJ = cJSON_Utils.o |
| 3 | CJSON_LIBNAME = libcjson |
| 4 | UTILS_LIBNAME = libcjson_utils |
| 5 | CJSON_TEST = cJSON_test |
| 6 | |
| 7 | CJSON_TEST_SRC = cJSON.c test.c |
| 8 | |
| 9 | LDLIBS = -lm |
| 10 | |
| 11 | LIBVERSION = 1.7.19 |
| 12 | CJSON_SOVERSION = 1 |
| 13 | UTILS_SOVERSION = 1 |
| 14 | |
| 15 | CJSON_SO_LDFLAG=-Wl,-soname=$(CJSON_LIBNAME).so.$(CJSON_SOVERSION) |
| 16 | UTILS_SO_LDFLAG=-Wl,-soname=$(UTILS_LIBNAME).so.$(UTILS_SOVERSION) |
| 17 | |
| 18 | PREFIX ?= /usr/local |
| 19 | INCLUDE_PATH ?= include/cjson |
| 20 | LIBRARY_PATH ?= lib |
| 21 | |
| 22 | INSTALL_INCLUDE_PATH = $(DESTDIR)$(PREFIX)/$(INCLUDE_PATH) |
| 23 | INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH) |
| 24 | |
| 25 | INSTALL ?= cp -a |
| 26 | |
| 27 | CC = gcc -std=c89 |
| 28 | |
| 29 | # validate gcc version for use fstack-protector-strong |
| 30 | MIN_GCC_VERSION = "4.9" |
| 31 | GCC_VERSION := "`$(CC) -dumpversion`" |
| 32 | IS_GCC_ABOVE_MIN_VERSION := $(shell expr "$(GCC_VERSION)" ">=" "$(MIN_GCC_VERSION)") |
| 33 | ifeq "$(IS_GCC_ABOVE_MIN_VERSION)" "1" |
| 34 | CFLAGS += -fstack-protector-strong |
| 35 | else |
| 36 | CFLAGS += -fstack-protector |
| 37 | endif |
| 38 | |
| 39 | PIC_FLAGS = -fPIC |
| 40 | R_CFLAGS = $(PIC_FLAGS) -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual -Wc++-compat -Wundef -Wswitch-default -Wconversion $(CFLAGS) |
| 41 | |
| 42 | uname := $(shell sh -c 'uname -s 2>/dev/null || echo false') |
| 43 | |
| 44 | #library file extensions |
| 45 | SHARED = so |
| 46 | STATIC = a |
| 47 | |
| 48 | ## create dynamic (shared) library on Darwin (base OS for MacOSX and IOS) |
| 49 | ifeq (Darwin, $(uname)) |
| 50 | SHARED = dylib |
| 51 | CJSON_SO_LDFLAG = "" |
| 52 | UTILS_SO_LDFLAG = "" |
| 53 | endif |
| 54 | |
| 55 | #cJSON library names |
| 56 | CJSON_SHARED = $(CJSON_LIBNAME).$(SHARED) |
| 57 | CJSON_SHARED_VERSION = $(CJSON_LIBNAME).$(SHARED).$(LIBVERSION) |
| 58 | CJSON_SHARED_SO = $(CJSON_LIBNAME).$(SHARED).$(CJSON_SOVERSION) |
| 59 | CJSON_STATIC = $(CJSON_LIBNAME).$(STATIC) |
| 60 | |
| 61 | #cJSON_Utils library names |
| 62 | UTILS_SHARED = $(UTILS_LIBNAME).$(SHARED) |
| 63 | UTILS_SHARED_VERSION = $(UTILS_LIBNAME).$(SHARED).$(LIBVERSION) |
| 64 | UTILS_SHARED_SO = $(UTILS_LIBNAME).$(SHARED).$(UTILS_SOVERSION) |
| 65 | UTILS_STATIC = $(UTILS_LIBNAME).$(STATIC) |
| 66 | |
| 67 | SHARED_CMD = $(CC) -shared -o |
| 68 | |
| 69 | .PHONY: all shared static tests clean install |
| 70 | |
| 71 | all: shared static tests |
| 72 | |
| 73 | shared: $(CJSON_SHARED) $(UTILS_SHARED) |
| 74 | |
| 75 | static: $(CJSON_STATIC) $(UTILS_STATIC) |
| 76 | |
| 77 | tests: $(CJSON_TEST) |
| 78 | |
| 79 | test: tests |
| 80 | ./$(CJSON_TEST) |
| 81 | |
| 82 | .c.o: |
| 83 | $(CC) -c $(R_CFLAGS) $< |
| 84 | |
| 85 | #tests |
| 86 | #cJSON |
| 87 | $(CJSON_TEST): $(CJSON_TEST_SRC) cJSON.h |
| 88 | $(CC) $(R_CFLAGS) $(CJSON_TEST_SRC) -o $@ $(LDLIBS) -I. |
| 89 | |
| 90 | #static libraries |
| 91 | #cJSON |
| 92 | $(CJSON_STATIC): $(CJSON_OBJ) |
| 93 | $(AR) rcs $@ $< |
| 94 | #cJSON_Utils |
| 95 | $(UTILS_STATIC): $(UTILS_OBJ) |
| 96 | $(AR) rcs $@ $< |
| 97 | |
| 98 | #shared libraries .so.1.0.0 |
| 99 | #cJSON |
| 100 | $(CJSON_SHARED_VERSION): $(CJSON_OBJ) |
| 101 | $(CC) -shared -o $@ $< $(CJSON_SO_LDFLAG) $(LDFLAGS) |
| 102 | #cJSON_Utils |
| 103 | $(UTILS_SHARED_VERSION): $(UTILS_OBJ) |
| 104 | $(CC) -shared -o $@ $< $(CJSON_OBJ) $(UTILS_SO_LDFLAG) $(LDFLAGS) |
| 105 | |
| 106 | #objects |
| 107 | #cJSON |
| 108 | $(CJSON_OBJ): cJSON.c cJSON.h |
| 109 | #cJSON_Utils |
| 110 | $(UTILS_OBJ): cJSON_Utils.c cJSON_Utils.h cJSON.h |
| 111 | |
| 112 | |
| 113 | #links .so -> .so.1 -> .so.1.0.0 |
| 114 | #cJSON |
| 115 | $(CJSON_SHARED_SO): $(CJSON_SHARED_VERSION) |
| 116 | ln -s $(CJSON_SHARED_VERSION) $(CJSON_SHARED_SO) |
| 117 | $(CJSON_SHARED): $(CJSON_SHARED_SO) |
| 118 | ln -s $(CJSON_SHARED_SO) $(CJSON_SHARED) |
| 119 | #cJSON_Utils |
| 120 | $(UTILS_SHARED_SO): $(UTILS_SHARED_VERSION) |
| 121 | ln -s $(UTILS_SHARED_VERSION) $(UTILS_SHARED_SO) |
| 122 | $(UTILS_SHARED): $(UTILS_SHARED_SO) |
| 123 | ln -s $(UTILS_SHARED_SO) $(UTILS_SHARED) |
| 124 | |
| 125 | #install |
| 126 | #cJSON |
| 127 | install-cjson: |
| 128 | mkdir -p $(INSTALL_LIBRARY_PATH) $(INSTALL_INCLUDE_PATH) |
| 129 | $(INSTALL) cJSON.h $(INSTALL_INCLUDE_PATH) |
| 130 | $(INSTALL) $(CJSON_SHARED) $(CJSON_SHARED_SO) $(CJSON_SHARED_VERSION) $(INSTALL_LIBRARY_PATH) |
| 131 | #cJSON_Utils |
| 132 | install-utils: install-cjson |
| 133 | $(INSTALL) cJSON_Utils.h $(INSTALL_INCLUDE_PATH) |
| 134 | $(INSTALL) $(UTILS_SHARED) $(UTILS_SHARED_SO) $(UTILS_SHARED_VERSION) $(INSTALL_LIBRARY_PATH) |
| 135 | |
| 136 | install: install-cjson install-utils |
| 137 | |
| 138 | #uninstall |
| 139 | #cJSON |
| 140 | uninstall-cjson: uninstall-utils |
| 141 | $(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED) |
| 142 | $(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED_VERSION) |
| 143 | $(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED_SO) |
| 144 | $(RM) $(INSTALL_INCLUDE_PATH)/cJSON.h |
| 145 | |
| 146 | #cJSON_Utils |
| 147 | uninstall-utils: |
| 148 | $(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED) |
| 149 | $(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED_VERSION) |
| 150 | $(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED_SO) |
| 151 | $(RM) $(INSTALL_INCLUDE_PATH)/cJSON_Utils.h |
| 152 | |
| 153 | remove-dir: |
| 154 | $(if $(wildcard $(INSTALL_LIBRARY_PATH)/*.*),,rmdir $(INSTALL_LIBRARY_PATH)) |
| 155 | $(if $(wildcard $(INSTALL_INCLUDE_PATH)/*.*),,rmdir $(INSTALL_INCLUDE_PATH)) |
| 156 | |
| 157 | uninstall: uninstall-utils uninstall-cjson remove-dir |
| 158 | |
| 159 | clean: |
| 160 | $(RM) $(CJSON_OBJ) $(UTILS_OBJ) #delete object files |
| 161 | $(RM) $(CJSON_SHARED) $(CJSON_SHARED_VERSION) $(CJSON_SHARED_SO) $(CJSON_STATIC) #delete cJSON |
| 162 | $(RM) $(UTILS_SHARED) $(UTILS_SHARED_VERSION) $(UTILS_SHARED_SO) $(UTILS_STATIC) #delete cJSON_Utils |
| 163 | $(RM) $(CJSON_TEST) #delete test |