Skip to content

Commit ff708a4

Browse files
committed
ext/odbc: get exact length for quoted connection strings
strlen has to scan the string until the end of the null terminator, we might as well do the same but scan for end quotes that need escaping.
1 parent ea67883 commit ff708a4

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

main/php_odbc_utils.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,16 @@ PHPAPI bool php_odbc_connstr_should_quote(const char *str)
7575
*/
7676
PHPAPI size_t php_odbc_connstr_estimate_quote_length(const char *in_str)
7777
{
78-
/* Assume all '}'. Include '{,' '}', and the null terminator too */
79-
return (strlen(in_str) * 2) + 3;
78+
/* Start with including the quotes ({}) and the null terminator */
79+
size_t size = 3;
80+
/* Scan the string like strlen, doubling each } character. */
81+
while (*in_str) {
82+
size++;
83+
if (*in_str++ == '}') {
84+
size++;
85+
}
86+
}
87+
return size;
8088
}
8189

8290
/**

0 commit comments

Comments
 (0)