From 53336f6b8848ba6c4de9c5db1608d7bd1f9ea515 Mon Sep 17 00:00:00 2001 From: Tommy Olofsson <tommy.olofsson.90@gmail.com> Date: Mon, 14 Apr 2014 15:18:47 +0200 Subject: [PATCH] Enabled stdio for VxWorks and fixed a potential bug where null was used as a buffer in the event of a failed memory allocation. --- lib/c/Makefile | 2 +- lib/c/labcomm_private.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/c/Makefile b/lib/c/Makefile index fcb53ba..c5af86b 100644 --- a/lib/c/Makefile +++ b/lib/c/Makefile @@ -10,7 +10,7 @@ ifeq ($(UNAME_S),Linux) CC=i586-wrs-vxworks-gcc LD=i586-wrs-vxworks-ld ALL_DEPS:=$(filter-out %.so.1, $(ALL_DEPS)) - CFLAGS:=$(CFLAGS) -DLABCOMM_COMPAT=\"labcomm_compat_vxworks.h\" -DLABCOMM_NO_STDIO + CFLAGS:=$(CFLAGS) -DLABCOMM_COMPAT=\"labcomm_compat_vxworks.h\" else @echo 'Invalid target.' endif diff --git a/lib/c/labcomm_private.h b/lib/c/labcomm_private.h index c74c4a7..e615799 100644 --- a/lib/c/labcomm_private.h +++ b/lib/c/labcomm_private.h @@ -270,6 +270,11 @@ static inline char *labcomm_read_string(struct labcomm_reader *r) length = labcomm_read_packed32(r); result = labcomm_memory_alloc(r->memory, 1, length + 1); + if (!result) { + on_error_fprintf(LABCOMM_ERROR_MEMORY, 4, "%d byte at %s:%d", + length+1, __FUNCTION__, __LINE__); + return NULL; + } for (pos = 0 ; pos < length ; pos++) { if (r->pos >= r->count) { labcomm_reader_fill(r, r->action_context); -- GitLab