]> granicus.if.org Git - php/commitdiff
Fix various instances of memcpy null ub
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 19 Jun 2019 14:53:42 +0000 (16:53 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 19 Jun 2019 15:27:09 +0000 (17:27 +0200)
ext/intl/converter/converter.c
ext/soap/php_sdl.c
ext/spl/spl_directory.c
ext/tidy/tidy.c

index 992a1bade7351524aa0a290a29539271205e4250..7b4109749e1666de37d76df0773b781252bee67f 100644 (file)
@@ -231,8 +231,16 @@ static void php_converter_to_u_callback(const void *context,
        zval zargs[4];
 
        ZVAL_LONG(&zargs[0], reason);
-       ZVAL_STRINGL(&zargs[1], args->source, args->sourceLimit - args->source);
-       ZVAL_STRINGL(&zargs[2], codeUnits, length);
+       if (args->source) {
+               ZVAL_STRINGL(&zargs[1], args->source, args->sourceLimit - args->source);
+       } else {
+               ZVAL_EMPTY_STRING(&zargs[1]);
+       }
+       if (codeUnits) {
+               ZVAL_STRINGL(&zargs[2], codeUnits, length);
+       } else {
+               ZVAL_EMPTY_STRING(&zargs[2]);
+       }
        ZVAL_LONG(&zargs[3], *pErrorCode);
 
        objval->to_cb.param_count    = 4;
index d9fea6d3b20ca7e246cc8e5c2f9613c9b7ac19ba..de4bf5c328625cc0b156847efb90fb825ba82912 100644 (file)
@@ -116,7 +116,9 @@ encodePtr get_encoder(sdlPtr sdl, const char *ns, const char *type)
        int len = ns_len + type_len + 1;
 
        nscat = emalloc(len + 1);
-       memcpy(nscat, ns, ns_len);
+       if (ns) {
+               memcpy(nscat, ns, ns_len);
+       }
        nscat[ns_len] = ':';
        memcpy(nscat+ns_len+1, type, type_len);
        nscat[len] = '\0';
index 676f107c3515dff4c880cf2f33ff7ddde10fe592..1fdaacb588e3764df78e5024051deaa0086e5983 100644 (file)
@@ -619,7 +619,7 @@ static HashTable *spl_filesystem_object_get_debug_info(zval *object, int *is_tem
 
        pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "pathName", sizeof("pathName")-1);
        path = spl_filesystem_object_get_pathname(intern, &path_len);
-       ZVAL_STRINGL(&tmp, path, path_len);
+       ZVAL_STRINGL(&tmp, path ? path : "", path_len);
        zend_symtable_update(rv, pnstr, &tmp);
        zend_string_release_ex(pnstr, 0);
 
@@ -891,7 +891,11 @@ SPL_METHOD(SplFileInfo, getPath)
        }
 
        path = spl_filesystem_object_get_path(intern, &path_len);
-       RETURN_STRINGL(path, path_len);
+       if (path) {
+               RETURN_STRINGL(path, path_len);
+       } else {
+               RETURN_EMPTY_STRING();
+       }
 }
 /* }}} */
 
index ee7defeac4a5c3edf0cda6b2c0050c4d1c149a7a..295ca8d8f000c3c3c9a2251a8a346de47087f08c 100644 (file)
@@ -783,7 +783,11 @@ static int tidy_doc_cast_handler(zval *in, zval *out, int type)
                        obj = Z_TIDY_P(in);
                        tidyBufInit(&output);
                        tidySaveBuffer (obj->ptdoc->doc, &output);
-                       ZVAL_STRINGL(out, (char *) output.bp, output.size ? output.size-1 : 0);
+                       if (output.size) {
+                               ZVAL_STRINGL(out, (char *) output.bp, output.size-1);
+                       } else {
+                               ZVAL_EMPTY_STRING(out);
+                       }
                        tidyBufFree(&output);
                        break;