]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[Core] scan-build: fix false-positive use-after-free in switch_xml_internal_dtd()
authorAndrey Volk <andywolk@gmail.com>
Sun, 25 Apr 2021 01:12:50 +0000 (04:12 +0300)
committerAndrey Volk <andywolk@gmail.com>
Tue, 19 Oct 2021 17:10:35 +0000 (20:10 +0300)
src/switch_xml.c

index b05358741c96258086269842c82e45b92844e499..94268da358bc4b3f6932bafc071299063d03ae23 100644 (file)
@@ -839,6 +839,8 @@ static short switch_xml_internal_dtd(switch_xml_root_t root, char *s, switch_siz
                if (!*s)
                        break;
                else if (!strncmp(s, "<!ENTITY", 8)) {  /* parse entity definitions */
+                       int use_pe;
+
                        c = s += strspn(s + 8, SWITCH_XML_WS) + 8;      /* skip white space separator */
                        n = s + strspn(s, SWITCH_XML_WS "%");   /* find name */
                        *(s = n + strcspn(n, SWITCH_XML_WS)) = ';';     /* append ; to name */
@@ -849,10 +851,11 @@ static short switch_xml_internal_dtd(switch_xml_root_t root, char *s, switch_siz
                                continue;
                        }
 
-                       for (i = 0, ent = (*c == '%') ? pe : root->ent; ent[i]; i++);
+                       use_pe = (*c == '%');
+                       for (i = 0, ent = (use_pe) ? pe : root->ent; ent[i]; i++);
                        sstmp = (char **) switch_must_realloc(ent, (i + 3) * sizeof(char *));   /* space for next ent */
                        ent = sstmp;
-                       if (*c == '%')
+                       if (use_pe)
                                pe = ent;
                        else
                                root->ent = ent;