From 0c5ac397961136be2f53e4c62f2655e54f20bf71 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 4 Sep 2014 21:55:27 +0200 Subject: [PATCH] Fix smart_str_append() Would segfault if src->s == NULL. --- ext/standard/php_smart_str.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h index c153fa884c..8b79e3edbc 100644 --- a/ext/standard/php_smart_str.h +++ b/ext/standard/php_smart_str.h @@ -158,9 +158,11 @@ static inline char *smart_str_print_unsigned(char *buf, zend_long num) { #define smart_str_append_off_t_ex(dest, num, type) \ smart_str_append_generic_ex((dest), (num), (type), zend_off_t, _signed) -#define smart_str_append_ex(dest, src, what) \ - smart_str_appendl_ex((dest), ((smart_str *)(src))->s->val, \ - ((smart_str *)(src))->s->len, (what)); +#define smart_str_append_ex(dest, src, what) do { \ + if ((src)->s && (src)->s->len) { \ + smart_str_appendl_ex((dest), (src)->s->val, (src)->s->len, (what)); \ + } \ +} while(0) #define smart_str_setl(dest, src, nlen) do { \ smart_str_free((dest)); \ -- 2.40.0