From 2dec14cd1dbf09755b0839859da1a942944a8376 Mon Sep 17 00:00:00 2001 From: Leo C Date: Sat, 21 Jul 2018 13:38:25 +0200 Subject: [PATCH 1/1] Remove xmalloc.c, fix potential 0-pointer derefenrence in cli.c. # Conflicts: # avr/cli.c --- avr/Tupfile | 4 ++-- avr/cli.c | 7 +------ avr/env.c | 5 ++--- avr/xmalloc.c | 32 -------------------------------- include/xmalloc.h | 8 -------- 5 files changed, 5 insertions(+), 51 deletions(-) delete mode 100644 avr/xmalloc.c delete mode 100644 include/xmalloc.h diff --git a/avr/Tupfile b/avr/Tupfile index d650514..5e1f305 100644 --- a/avr/Tupfile +++ b/avr/Tupfile @@ -10,8 +10,7 @@ SRC += cli.c cli_readline.c command.c command_tbl.c SRC += cmd_run.c cmd_boot.c cmd_misc.c SRC += cmd_date.c cmd_mem.c cmd_gpio.c cmd_attach.c SRC += cmd_loadihex.c cmd_loadcpm3.c cmd_sd.c cmd_fat.c -SRC += env.c xmalloc.c con-utils.c print-utils.c -SRC += getopt-min.c eval_arg.c +SRC += env.c con-utils.c print-utils.c getopt-min.c eval_arg.c SRC += timer.c serial.c i2c.c bcd.c pcf8583.c mmc.c SRC += background.c z180-serv.c z80-if.c gpio.c SRC += $(FATFS) @@ -97,6 +96,7 @@ ASFLAGS += -mmcu=$(MCU_TARGET) -x assembler-with-cpp $(ASFLAGS) # Linker flags LDFLAGS += -Wl,--gc-sections LDFLAGS += -Wl,--cref +#LDFLAGS += -flto -Os # Assemble: create object files from assembler source files. #.S.o: diff --git a/avr/cli.c b/avr/cli.c index 8a62bc0..b47603a 100644 --- a/avr/cli.c +++ b/avr/cli.c @@ -12,15 +12,10 @@ */ #include "cli.h" -#include "common.h" - -#include +#include "command.h" #include -#include -#include #include "config.h" -#include "command.h" #include "debug.h" #include "env.h" #include "cli_readline.h" diff --git a/avr/env.c b/avr/env.c index 4f37590..b2b4e6f 100644 --- a/avr/env.c +++ b/avr/env.c @@ -9,7 +9,6 @@ #include "config.h" #include "debug.h" -#include "xmalloc.h" #include "crc.h" #include "getopt-min.h" @@ -195,7 +194,7 @@ int envlist_import(uint8_t flags) return -1; } - np = (char *) xmalloc(len+1); + np = (char *) malloc(len+1); if (np == NULL) { printf_P(PSTR("## Can't malloc %d bytes\n"), len+1); return 1; @@ -488,7 +487,7 @@ command_ret_t _do_env_set(uint_fast8_t flag, int argc, char * const argv[]) for (i = 2, len += 1; i < argc; ++i) len += strlen(argv[i]) + 1; - value = xmalloc(len); + value = malloc(len); if (value == NULL) { printf_P(PSTR("## Can't malloc %d bytes\n"), len); return CMD_RET_FAILURE; diff --git a/avr/xmalloc.c b/avr/xmalloc.c deleted file mode 100644 index d42d5c9..0000000 --- a/avr/xmalloc.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * (C) Copyright 2014 Leo C. - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include -#include "debug.h" -#include "xmalloc.h" - -void* xmalloc(size_t size) -{ - void *p; - - p = malloc(size); - - if (p == NULL) - debug("*** Out of memory!\n"); - - return p; -} - - -void* xrealloc(void *p, size_t size) -{ - p = realloc(p, size); - - if (p == NULL) - debug("*** Out of memory!\n"); - - return p; -} diff --git a/include/xmalloc.h b/include/xmalloc.h deleted file mode 100644 index cb0019f..0000000 --- a/include/xmalloc.h +++ /dev/null @@ -1,8 +0,0 @@ - -#ifndef XMALLOC_H -#define XMALLOC_H - -void* xmalloc(size_t size); -void* xrealloc(void *p, size_t size); - -#endif /* XMALLOC_H */ -- 2.39.2