]> granicus.if.org Git - php/commitdiff
Fix smart_str_append()
authorNikita Popov <nikic@php.net>
Thu, 4 Sep 2014 19:55:27 +0000 (21:55 +0200)
committerNikita Popov <nikic@php.net>
Thu, 4 Sep 2014 19:55:27 +0000 (21:55 +0200)
Would segfault if src->s == NULL.

ext/standard/php_smart_str.h

index c153fa884cf861b4397daf2e31495465dfbfd5f0..8b79e3edbcbd117c7c2f0f440621597edf3588c2 100644 (file)
@@ -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));                                                                                 \