Skip to content

Commit 42f3972

Browse files
author
Ilia Alshanetsky
committed
Avoid strcpy() usage
1 parent 34f08a3 commit 42f3972

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Diff for: ext/pdo/pdo_sql_parser.re

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ safe:
213213
param->param_type TSRMLS_CC)) {
214214
/* bork */
215215
ret = -1;
216-
strcpy(stmt->error_code, stmt->dbh->error_code);
216+
strncpy(stmt->error_code, stmt->dbh->error_code, 6);
217217
if (buf) {
218218
efree(buf);
219219
}
@@ -254,7 +254,7 @@ safe:
254254
param->param_type TSRMLS_CC)) {
255255
/* bork */
256256
ret = -1;
257-
strcpy(stmt->error_code, stmt->dbh->error_code);
257+
strncpy(stmt->error_code, stmt->dbh->error_code, 6);
258258
goto clean_up;
259259
}
260260
plc->freeq = 1;

Diff for: ext/pdo_sqlite/sqlite_driver.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,33 @@ int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int li
4747
}
4848
einfo->errmsg = pestrdup((char*)sqlite3_errmsg(H->db), dbh->is_persistent);
4949
} else { /* no error */
50-
strcpy(*pdo_err, PDO_ERR_NONE);
50+
strncpy(*pdo_err, PDO_ERR_NONE, sizeof(PDO_ERR_NONE));
5151
return 0;
5252
}
5353
switch (einfo->errcode) {
5454
case SQLITE_NOTFOUND:
55-
strcpy(*pdo_err, "42S02");
55+
strncpy(*pdo_err, "42S02", sizeof("42S02"));
5656
break;
5757

5858
case SQLITE_INTERRUPT:
59-
strcpy(*pdo_err, "01002");
59+
strncpy(*pdo_err, "01002", sizeof("01002"));
6060
break;
6161

6262
case SQLITE_NOLFS:
63-
strcpy(*pdo_err, "HYC00");
63+
strncpy(*pdo_err, "HYC00", sizeof("HYC00"));
6464
break;
6565

6666
case SQLITE_TOOBIG:
67-
strcpy(*pdo_err, "22001");
67+
strncpy(*pdo_err, "22001", sizeof("22001"));
6868
break;
6969

7070
case SQLITE_CONSTRAINT:
71-
strcpy(*pdo_err, "23000");
71+
strncpy(*pdo_err, "23000", sizeof("23000"));
7272
break;
7373

7474
case SQLITE_ERROR:
7575
default:
76-
strcpy(*pdo_err, "HY000");
76+
strncpy(*pdo_err, "HY000", sizeof("HY000"));
7777
break;
7878
}
7979

0 commit comments

Comments
 (0)