From: Ilia Alshanetsky Date: Sat, 24 Feb 2007 18:00:56 +0000 (+0000) Subject: strncpy() -> strlcpy() X-Git-Tag: php-5.2.2RC1~283 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9783f5f1f3dd69e06fc5ede7fb6715957bc43955;p=php strncpy() -> strlcpy() --- diff --git a/ext/dbase/dbf_head.c b/ext/dbase/dbf_head.c index 9c9363dfbb..0f9ad61461 100644 --- a/ext/dbase/dbf_head.c +++ b/ext/dbase/dbf_head.c @@ -184,7 +184,7 @@ int put_dbf_field(dbhead_t *dbh, dbfield_t *dbf) /* build the on disk field info */ scp = dbf->db_fname; dcp = dbfield.dbf_name; - strncpy(dbfield.dbf_name, dbf->db_fname, DBF_NAMELEN); + strlcpy(dbfield.dbf_name, dbf->db_fname, DBF_NAMELEN); dbfield.dbf_type = dbf->db_type; switch (dbf->db_type) { diff --git a/ext/dbase/dbf_rec.c b/ext/dbase/dbf_rec.c index 6e872d3fb7..86db498666 100644 --- a/ext/dbase/dbf_rec.c +++ b/ext/dbase/dbf_rec.c @@ -152,8 +152,7 @@ char *get_field_val(char *rp, dbfield_t *fldp, char *cp) if ( !cp ) cp = (char *)malloc(flen + 1); if ( cp ) { - strncpy(cp, &rp[fldp->db_foffset], flen); - cp[flen] = 0; + strlcpy(cp, &rp[fldp->db_foffset], flen + 1); } return cp; } diff --git a/ext/gd/libgd/gd_gif_in.c b/ext/gd/libgd/gd_gif_in.c index e3d635b31f..a770e16893 100644 --- a/ext/gd/libgd/gd_gif_in.c +++ b/ext/gd/libgd/gd_gif_in.c @@ -133,8 +133,7 @@ gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr fd) /* {{{ */ if (strncmp((char *)buf,"GIF",3) != 0) { return 0; } - strncpy(version, (char *)buf + 3, 3); - version[3] = '\0'; + strlcpy(version, (char *)buf + 3, sizeof(version)); if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) { return 0; diff --git a/ext/interbase/ibase_query.c b/ext/interbase/ibase_query.c index 3de5879688..bb2bfe6184 100644 --- a/ext/interbase/ibase_query.c +++ b/ext/interbase/ibase_query.c @@ -603,9 +603,8 @@ static int _php_ibase_bind_array(zval *val, char *buf, unsigned long buf_size, / break; default: convert_to_string(val); - strncpy(buf, Z_STRVAL_P(val), array->el_size); - buf[array->el_size-1] = '\0'; - } + strlcpy(buf, Z_STRVAL_P(val), buf_size); + } } } return SUCCESS; diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c index f7ab90f14a..667bd8227a 100644 --- a/ext/pdo_firebird/firebird_statement.c +++ b/ext/pdo_firebird/firebird_statement.c @@ -655,8 +655,7 @@ static int firebird_stmt_set_attribute(pdo_stmt_t *stmt, long attr, zval *val TS RECORD_ERROR(stmt); return 0; } - strncpy(S->name, Z_STRVAL_P(val), sizeof(S->name)); - S->name[sizeof(S->name)] = 0; + strlcpy(S->name, Z_STRVAL_P(val), sizeof(S->name)); break; } return 1; diff --git a/ext/wddx/wddx.c b/ext/wddx/wddx.c index 4c883ded2c..6bdbb05ed3 100644 --- a/ext/wddx/wddx.c +++ b/ext/wddx/wddx.c @@ -1034,10 +1034,9 @@ static void php_wddx_process_data(void *user_data, const XML_Char *s, int len) Z_STRVAL_P(ent->data) = estrndup(decoded, decoded_len); Z_STRLEN_P(ent->data) = decoded_len; } else { - Z_STRVAL_P(ent->data) = erealloc(Z_STRVAL_P(ent->data), - Z_STRLEN_P(ent->data) + decoded_len + 1); - strncpy(Z_STRVAL_P(ent->data)+Z_STRLEN_P(ent->data), decoded, decoded_len); Z_STRLEN_P(ent->data) += decoded_len; + Z_STRVAL_P(ent->data) = erealloc(Z_STRVAL_P(ent->data), Z_STRLEN_P(ent->data) + 1); + strlcpy(Z_STRVAL_P(ent->data) + Z_STRLEN_P(ent->data), decoded, Z_STRLEN_P(ent->data) + 1); Z_STRVAL_P(ent->data)[Z_STRLEN_P(ent->data)] = '\0'; }