]> granicus.if.org Git - php/commitdiff
Replace strncat in filter implementation
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 23 Aug 2019 13:51:57 +0000 (15:51 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 23 Aug 2019 14:18:50 +0000 (16:18 +0200)
In this case we already know exactly where we need to write, no
need to use strncat at all.

ext/standard/user_filters.c
main/streams/filter.c

index 4fb177a3ee8293f7fd40b64ffc646ec9ccb6c1ec..6cba49b03018ace5e1728beed2af547927e6ce86 100644 (file)
@@ -292,8 +292,9 @@ static php_stream_filter *user_filter_factory_create(const char *filtername,
                        memcpy(wildcard, filtername, len + 1); /* copy \0 */
                        period = wildcard + (period - filtername);
                        while (period) {
-                               *period = '\0';
-                               strncat(wildcard, ".*", 2);
+                               ZEND_ASSERT(period[0] == '.');
+                               period[1] = '*';
+                               period[2] = '\0';
                                if (NULL != (fdat = zend_hash_str_find_ptr(BG(user_filter_map), wildcard, strlen(wildcard)))) {
                                        period = NULL;
                                } else {
index afc1f3b8e54ed18e7b8bf20ea032462190d1edc1..7fdbd0c3bfe39fe2455705ee385de92b666dff1b 100644 (file)
@@ -239,8 +239,9 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval
                memcpy(wildname, filtername, n+1);
                period = wildname + (period - filtername);
                while (period && !filter) {
-                       *period = '\0';
-                       strncat(wildname, ".*", 2);
+                       ZEND_ASSERT(period[0] == '.');
+                       period[1] = '*';
+                       period[2] = '\0';
                        if (NULL != (factory = zend_hash_str_find_ptr(filter_hash, wildname, strlen(wildname)))) {
                                filter = factory->create_filter(filtername, filterparams, persistent);
                        }