]> granicus.if.org Git - php/commitdiff
Fix potentially uninitialized warnings in phpdbg
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Apr 2019 09:20:29 +0000 (11:20 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Apr 2019 09:46:03 +0000 (11:46 +0200)
sapi/phpdbg/phpdbg.c
sapi/phpdbg/phpdbg_frame.c
sapi/phpdbg/phpdbg_info.c
sapi/phpdbg/phpdbg_out.c
sapi/phpdbg/phpdbg_prompt.c
sapi/phpdbg/phpdbg_utils.c
sapi/phpdbg/phpdbg_wait.c
sapi/phpdbg/phpdbg_watch.c

index 51c6cde122271e55c32cd729f71317b0ae07c1c2..b9149287bae891e10afe626c74e7c2b1d32dd12c 100644 (file)
@@ -671,11 +671,11 @@ static PHP_FUNCTION(phpdbg_end_oplog)
 
        {
                zend_string *last_file = NULL;
-               HashTable *file_ht;
+               HashTable *file_ht = NULL;
                zend_string *last_function = (void *)~(uintptr_t)0;
                zend_class_entry *last_scope = NULL;
 
-               HashTable *insert_ht;
+               HashTable *insert_ht = NULL;
                zend_long insert_idx;
 
                do {
@@ -717,6 +717,7 @@ static PHP_FUNCTION(phpdbg_end_oplog)
                                insert_idx = cur->op->lineno;
                        }
 
+                       ZEND_ASSERT(insert_ht && file_ht);
                        {
                                zval *num = zend_hash_index_find(insert_ht, insert_idx);
                                if (!num) {
index fb7acc20cebee8b4a229061fc3ec3cf9d8ded087..912089ea2303d26003db0262fdd2454713dcf760 100644 (file)
@@ -171,7 +171,7 @@ void phpdbg_switch_frame(int frame) /* {{{ */
 
 static void phpdbg_dump_prototype(zval *tmp) /* {{{ */
 {
-       zval *funcname, *class, class_zv, *type, *args, *argstmp;
+       zval *funcname, *class, class_zv, *args, *argstmp;
 
        funcname = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("function"));
 
@@ -183,21 +183,22 @@ static void phpdbg_dump_prototype(zval *tmp) /* {{{ */
        }
 
        if (class) {
-               type = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("type"));
+               zval *type = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("type"));
+
+               phpdbg_xml(" symbol=\"%s%s%s\"", Z_STRVAL_P(class), Z_STRVAL_P(type), Z_STRVAL_P(funcname));
+               phpdbg_out("%s%s%s(", Z_STRVAL_P(class), Z_STRVAL_P(type), Z_STRVAL_P(funcname));
+       } else {
+               phpdbg_xml(" symbol=\"%s\"", Z_STRVAL_P(funcname));
+               phpdbg_out("%s(", Z_STRVAL_P(funcname));
        }
 
        args = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("args"));
-
-       phpdbg_xml(" symbol=\"%s%s%s\"", class ? Z_STRVAL_P(class) : "", class ? Z_STRVAL_P(type) : "", Z_STRVAL_P(funcname));
-
        if (args) {
                phpdbg_xml(">");
        } else {
                phpdbg_xml(" />");
        }
 
-       phpdbg_out("%s%s%s(", class ? Z_STRVAL_P(class) : "", class ? Z_STRVAL_P(type) : "", Z_STRVAL_P(funcname));
-
        if (args) {
                const zend_function *func = NULL;
                const zend_arg_info *arginfo = NULL;
index 167ada399a22e669da84ca2f9d4ac7352f2d48f6..bcec3361fc92e3496027dde0ae3bef4eb9d9fa6a 100644 (file)
@@ -343,11 +343,11 @@ PHPDBG_INFO(literal) /* {{{ */
 PHPDBG_INFO(memory) /* {{{ */
 {
        size_t used, real, peak_used, peak_real;
-       zend_mm_heap *heap;
+       zend_mm_heap *orig_heap = NULL;
        zend_bool is_mm;
 
        if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
-               heap = zend_mm_set_heap(phpdbg_original_heap_sigsafe_mem());
+               orig_heap = zend_mm_set_heap(phpdbg_original_heap_sigsafe_mem());
        }
        if ((is_mm = is_zend_mm())) {
                used = zend_memory_usage(0);
@@ -355,8 +355,8 @@ PHPDBG_INFO(memory) /* {{{ */
                peak_used = zend_memory_peak_usage(0);
                peak_real = zend_memory_peak_usage(1);
        }
-       if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
-               zend_mm_set_heap(heap);
+       if (orig_heap) {
+               zend_mm_set_heap(orig_heap);
        }
 
        if (is_mm) {
index 95f27b3c6fd84af55d8ecb3c6e446b0593f3bc37..88981e5c6fb693388d3fd9ad830d600e9ae42e58 100644 (file)
@@ -1030,9 +1030,8 @@ static int phpdbg_process_print(int fd, int type, const char *tag, const char *m
                                } else {
                                        phpdbg_mixed_write(fd, msg, msglen);
                                }
-                               return msglen;
                        }
-               break;
+                       return msglen;
 
                /* no formatting on logging output */
                case P_LOG:
@@ -1046,6 +1045,7 @@ static int phpdbg_process_print(int fd, int type, const char *tag, const char *m
                                }
                        }
                        break;
+               EMPTY_SWITCH_DEFAULT_CASE()
        }
 
        if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
index c962ce52c30f2d248e4906bc2bab906791a5c595..e1bfeb45da8ffeda705a77c4082f3c9243773959 100644 (file)
@@ -1687,33 +1687,33 @@ int phpdbg_interactive(zend_bool allow_async_unsafe, char *input) /* {{{ */
        return ret;
 } /* }}} */
 
+static inline void list_code() {
+       if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) {
+               const char *file_char = zend_get_executed_filename();
+               zend_string *file = zend_string_init(file_char, strlen(file_char), 0);
+               phpdbg_list_file(file, 3, zend_get_executed_lineno()-1, zend_get_executed_lineno());
+               efree(file);
+       }
+}
+
 /* code may behave weirdly if EG(exception) is set; thus backup it */
 #define DO_INTERACTIVE(allow_async_unsafe) do { \
-       const zend_op *backup_opline; \
-       const zend_op *before_ex; \
        if (exception) { \
+               const zend_op *before_ex = EG(opline_before_exception); \
+               const zend_op *backup_opline = NULL; \
                if (EG(current_execute_data) && EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) { \
                        backup_opline = EG(current_execute_data)->opline; \
                } \
-               before_ex = EG(opline_before_exception); \
                GC_ADDREF(exception); \
                zend_clear_exception(); \
-       } \
-       if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { \
-               const char *file_char = zend_get_executed_filename(); \
-               zend_string *file = zend_string_init(file_char, strlen(file_char), 0); \
-               phpdbg_list_file(file, 3, zend_get_executed_lineno()-1, zend_get_executed_lineno()); \
-               efree(file); \
-       } \
-       \
-       switch (phpdbg_interactive(allow_async_unsafe, NULL)) { \
-               zval zv; \
-               case PHPDBG_LEAVE: \
-               case PHPDBG_FINISH: \
-               case PHPDBG_UNTIL: \
-               case PHPDBG_NEXT: \
-                       if (exception) { \
-                               if (EG(current_execute_data) && EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type) \
+               list_code(); \
+               switch (phpdbg_interactive(allow_async_unsafe, NULL)) { \
+                       zval zv; \
+                       case PHPDBG_LEAVE: \
+                       case PHPDBG_FINISH: \
+                       case PHPDBG_UNTIL: \
+                       case PHPDBG_NEXT: \
+                               if (backup_opline \
                                 && (backup_opline->opcode == ZEND_HANDLE_EXCEPTION || backup_opline->opcode == ZEND_CATCH)) { \
                                        EG(current_execute_data)->opline = backup_opline; \
                                        EG(exception) = exception; \
@@ -1722,11 +1722,12 @@ int phpdbg_interactive(zend_bool allow_async_unsafe, char *input) /* {{{ */
                                        zend_throw_exception_internal(&zv); \
                                } \
                                EG(opline_before_exception) = before_ex; \
-                       } \
-                       /* fallthrough */ \
-               default: \
-                       goto next; \
+               } \
+       } else { \
+               list_code(); \
+               phpdbg_interactive(allow_async_unsafe, NULL); \
        } \
+       goto next; \
 } while (0)
 
 void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */
index c40349f2a0c5458083477489418b6278dc92c8fc..38e3d383776fcc58809d47d0a34394f471691ce3 100644 (file)
@@ -430,7 +430,7 @@ PHPDBG_API int phpdbg_parse_variable(char *input, size_t len, HashTable *parent,
 PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_with_arg_func callback, phpdbg_parse_var_with_arg_func step_cb, zend_bool silent, void *arg) {
        int ret = FAILURE;
        zend_bool new_index = 1;
-       char *last_index;
+       char *last_index = NULL;
        size_t index_len = 0;
        zval *zv;
 
index de0ecbe59f06dc0bb0da4e92cb7157d947a56eb6..738b4669f2d2e5f953354b571a9d3cbc3d6b78c4 100644 (file)
@@ -243,7 +243,7 @@ void phpdbg_webdata_decompress(char *msg, int len) {
                zend_extension *extension;
                zend_llist_position pos;
                zval *name = NULL;
-               zend_string *strkey;
+               zend_string *strkey = NULL;
 
                extension = (zend_extension *) zend_llist_get_first_ex(&zend_extensions, &pos);
                while (extension) {
@@ -257,6 +257,7 @@ void phpdbg_webdata_decompress(char *msg, int len) {
                                        break;
                                }
                                name = NULL;
+                               strkey = NULL;
                        } ZEND_HASH_FOREACH_END();
 
                        if (name) {
@@ -283,6 +284,7 @@ void phpdbg_webdata_decompress(char *msg, int len) {
                                pefree(elm, zend_extensions.persistent);
                                zend_extensions.count--;
                        } else {
+                               ZEND_ASSERT(strkey);
                                zend_hash_del(Z_ARRVAL_P(zvp), strkey);
                        }
                }
index 35d316b8ea4643af50fb8c99e157c61931d20f69..d9f9f8673fe4cc4c7668c2a97aa0304666cc82b0 100644 (file)
@@ -1014,13 +1014,14 @@ void phpdbg_check_watchpoint(phpdbg_watchpoint_t *watch) {
        }
        if (watch->type == WATCH_ON_BUCKET) {
                if (watch->backup.bucket.key != watch->addr.bucket->key || (watch->backup.bucket.key != NULL && watch->backup.bucket.h != watch->addr.bucket->h)) {
-                       phpdbg_watch_element *element;
+                       phpdbg_watch_element *element = NULL;
                        zval *new;
 
                        ZEND_HASH_FOREACH_PTR(&watch->elements, element) {
                                break;
                        } ZEND_HASH_FOREACH_END();
 
+                       ZEND_ASSERT(element); /* elements must be non-empty */
                        new = zend_symtable_find(element->parent_container, element->name_in_parent);
 
                        if (!new) {