Skip to content

Commit 249d2da

Browse files
authored
ext/pdo: Use memcpy instead of strlcpy for copying default error code (#17290)
They have identical sizes, so there is no need for 'extra' safety. See https://nrk.neocities.org/articles/not-a-fan-of-strlcpy for a rationale against the usage of strlcpy
1 parent 1969955 commit 249d2da

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ext/pdo/php_pdo_error.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@
2222
PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt);
2323

2424
#define PDO_DBH_CLEAR_ERR() do { \
25-
strlcpy(dbh->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE)); \
25+
ZEND_ASSERT(sizeof(dbh->error_code) == sizeof(PDO_ERR_NONE)); \
26+
memcpy(dbh->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE)); \
2627
if (dbh->query_stmt) { \
2728
dbh->query_stmt = NULL; \
2829
zval_ptr_dtor(&dbh->query_stmt_zval); \
2930
} \
3031
} while (0)
31-
#define PDO_STMT_CLEAR_ERR() strcpy(stmt->error_code, PDO_ERR_NONE)
32+
#define PDO_STMT_CLEAR_ERR() do { \
33+
ZEND_ASSERT(sizeof(stmt->error_code) == sizeof(PDO_ERR_NONE)); \
34+
memcpy(stmt->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE)); \
35+
} while (0)
3236
#define PDO_HANDLE_DBH_ERR() if (strcmp(dbh->error_code, PDO_ERR_NONE)) { pdo_handle_error(dbh, NULL); }
3337
#define PDO_HANDLE_STMT_ERR() if (strcmp(stmt->error_code, PDO_ERR_NONE)) { pdo_handle_error(stmt->dbh, stmt); }
3438

0 commit comments

Comments
 (0)