note 44256 deleted from internals2.ze1.zendapi by cmb
| From: | cmb@php.net | Date: | Sun, 10 Jan 2021 13:26:13 +0000 |
| Subject: | note 44256 deleted from internals2.ze1.zendapi by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216130@lists.php.net to get a copy of this message | ||
Note Submitter: ppmm at wuxinan dot net
----
In fact, empty string is not writeable, even when we add an slash after the type decl. Say the
implementation of my_test() is like this:
char *s;
int s_len;
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s/", &s, &s_len)
and you pass an empty string my_test("") from the PHP script, then s[0] is not writeable.
You will get a seg fault. The reason is that Zend doesn't emalloc a new copy of the empty
string dynamically, instead it just assigns the empty_string (which is defined at compile time and
located in unwriteable data seg) pointer to s.