]> granicus.if.org Git - php/commitdiff
fix potential leak, improve length checks
authorAntony Dovgal <tony2001@php.net>
Wed, 20 Dec 2006 23:36:43 +0000 (23:36 +0000)
committerAntony Dovgal <tony2001@php.net>
Wed, 20 Dec 2006 23:36:43 +0000 (23:36 +0000)
ext/standard/string.c

index f51da3f5a9a9832882052df1dbf6964ba59652ce..d92d2573675ebcabeef931f471d53da457f41df3 100644 (file)
@@ -6154,7 +6154,7 @@ int php_u_tag_find(UChar *tag, int len, UChar *set, int set_len)
        UChar *norm, *n;
        int state = 0, done = 0;
 
-       if (!len) {
+       if (len <= 0) {
                return 0;
        }
 
@@ -6205,7 +6205,13 @@ int php_u_tag_find(UChar *tag, int len, UChar *set, int set_len)
 int php_tag_find(char *tag, int len, char *set) {
        char c, *n, *t;
        int state=0, done=0;
-       char *norm = emalloc(len+1);
+       char *norm;
+
+       if (len <= 0) {
+               return 0;
+       }
+       
+       norm = emalloc(len+1);
 
        n = norm;
        t = tag;
@@ -6215,9 +6221,6 @@ int php_tag_find(char *tag, int len, char *set) {
           and turn any <a whatever...> into just <a> and any </tag>
           into <tag>
        */
-       if (!len) {
-               return 0;
-       }
        while (!done) {
                switch (c) {
                        case '<':