From 49694c78df79608473e07c8e2d7002b7c7749d37 Mon Sep 17 00:00:00 2001 From: jcorporation Date: Mon, 11 Jun 2018 20:52:24 +0100 Subject: [PATCH] Enable gcc sanitizers --- CMakeLists.txt | 2 +- src/mongoose.c | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d918bc..0819398 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ include_directories(${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR} ${LIBMPDCLIENT_I include(CheckCSourceCompiles) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -ggdb -pedantic -D_FORTIFY_SOURCE=2 -fstack-protector -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=shift -fsanitize=integer-divide-by-zero -fsanitize=unreachable -fsanitize=vla-bound -fsanitize=null -fsanitize=return -fsanitize=signed-integer-overflow -fsanitize=bounds -fsanitize=bounds-strict -fsanitize=alignment -fsanitize=object-size -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fsanitize=nonnull-attribute -fsanitize=returns-nonnull-attribute -fsanitize=bool -fsanitize=enum -fsanitize=vptr -static-libasan") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -pedantic") if(WITH_IPV6) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS NS_ENABLE_IPV6) diff --git a/src/mongoose.c b/src/mongoose.c index 8d373c9..94d1c68 100644 --- a/src/mongoose.c +++ b/src/mongoose.c @@ -670,16 +670,18 @@ static int ns_parse_address(const char *str, union socket_address *sa, *use_ssl = 0; cert[0] = ca[0] = '\0'; - if (memcmp(str, "ssl://", 6) == 0) { - str += 6; - *use_ssl = 1; - } else if (memcmp(str, "udp://", 6) == 0) { - str += 6; - *proto = SOCK_DGRAM; - } else if (memcmp(str, "tcp://", 6) == 0) { - str += 6; + if (strlen(str)>=6) { + if (memcmp(str, "ssl://", 6) == 0) { + str += 6; + *use_ssl = 1; + } else if (memcmp(str, "udp://", 6) == 0) { + str += 6; + *proto = SOCK_DGRAM; + } else if (memcmp(str, "tcp://", 6) == 0) { + str += 6; + } } - + if (sscanf(str, "%u.%u.%u.%u:%u%n", &a, &b, &c, &d, &port, &len) == 5) { // Bind to a specific IPv4 address, e.g. 192.168.1.5:8080 sa->sin.sin_addr.s_addr = htonl((a << 24) | (b << 16) | (c << 8) | d);