summaryrefslogtreecommitdiff
path: root/ext/dbase
diff options
context:
space:
mode:
authorMark A. Hershberger <mah@debian.(none)>2009-03-25 00:37:27 -0400
committerMark A. Hershberger <mah@debian.(none)>2009-03-25 00:37:27 -0400
commit2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b (patch)
tree41ccc042009cba53e4ce43e727fcba4c1cfbf7f3 /ext/dbase
parentd29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (diff)
downloadphp-upstream/5.2.2.tar.gz
Imported Upstream version 5.2.2upstream/5.2.2
Diffstat (limited to 'ext/dbase')
-rw-r--r--ext/dbase/dbase.c16
-rw-r--r--ext/dbase/dbf_head.c10
-rw-r--r--ext/dbase/dbf_misc.c7
-rw-r--r--ext/dbase/dbf_rec.c3
-rw-r--r--ext/dbase/package.xml2
-rw-r--r--ext/dbase/php_dbase.h4
-rw-r--r--ext/dbase/tests/001.phpt4
-rw-r--r--ext/dbase/tests/002.phpt4
8 files changed, 28 insertions, 22 deletions
diff --git a/ext/dbase/dbase.c b/ext/dbase/dbase.c
index b905d89bd..3a42c4526 100644
--- a/ext/dbase/dbase.c
+++ b/ext/dbase/dbase.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dbase.c,v 1.74.2.2.2.5 2006/10/10 23:01:23 tony2001 Exp $ */
+/* $Id: dbase.c,v 1.74.2.2.2.9 2007/02/25 23:17:12 tony2001 Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -129,10 +129,15 @@ PHP_FUNCTION(dbase_open)
convert_to_string_ex(dbf_name);
convert_to_long_ex(options);
+ if (!Z_STRLEN_PP(dbf_name)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "The filename cannot be empty.");
+ RETURN_FALSE;
+ }
+
if (Z_LVAL_PP(options) == 1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot open %s in write-only mode", Z_STRVAL_PP(dbf_name));
RETURN_FALSE;
- } else if (Z_LVAL_PP(options) < 0) {
+ } else if (Z_LVAL_PP(options) < 0 || Z_LVAL_PP(options) > 3) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid access mode %ld", Z_LVAL_PP(options));
RETURN_FALSE;
}
@@ -616,6 +621,11 @@ PHP_FUNCTION(dbase_create)
num_fields = zend_hash_num_elements(Z_ARRVAL_PP(fields));
+ if (num_fields <= 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create database without fields");
+ RETURN_FALSE;
+ }
+
/* have to use regular malloc() because this gets free()d by
code in the dbase library */
dbh = (dbhead_t *)malloc(sizeof(dbhead_t));
diff --git a/ext/dbase/dbf_head.c b/ext/dbase/dbf_head.c
index 42935c2ea..0f9ad6146 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) {
@@ -215,7 +215,7 @@ void put_dbf_info(dbhead_t *dbh)
int fcnt;
if ((cp = db_cur_date(NULL))) {
- strncpy(dbh->db_date, cp, 8);
+ strlcpy(dbh->db_date, cp, 8);
free(cp);
}
put_dbf_head(dbh);
@@ -232,16 +232,16 @@ char *get_dbf_f_fmt(dbfield_t *dbf)
/* build the field format for printf */
switch (dbf->db_type) {
case 'C':
- sprintf(format, "%%-%ds", dbf->db_flen);
+ snprintf(format, sizeof(format), "%%-%ds", dbf->db_flen);
break;
case 'N':
case 'L':
case 'D':
case 'F':
- sprintf(format, "%%%ds", dbf->db_flen);
+ snprintf(format, sizeof(format), "%%%ds", dbf->db_flen);
break;
case 'M':
- strcpy(format, "%s");
+ strlcpy(format, "%s", sizeof(format));
break;
default:
return NULL;
diff --git a/ext/dbase/dbf_misc.c b/ext/dbase/dbf_misc.c
index ad17bd4e3..d57278396 100644
--- a/ext/dbase/dbf_misc.c
+++ b/ext/dbase/dbf_misc.c
@@ -114,12 +114,7 @@ void db_set_date(char *cp, int year, int month, int day)
month = 0;
if (day > 31)
day = 0;
- sprintf(cp, "%d", year);
- cp[4] = month / 10 + '0';
- cp[5] = month % 10 + '0';
- cp[6] = day / 10 + '0';
- cp[7] = day % 10 + '0';
- cp[8] = 0;
+ snprintf(cp, 9, "%04d%02d%02d", year, month, day);
}
int db_date_year(char *cp)
diff --git a/ext/dbase/dbf_rec.c b/ext/dbase/dbf_rec.c
index 6e872d3fb..86db49866 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/dbase/package.xml b/ext/dbase/package.xml
index f0a30a5a2..a1c576fa1 100644
--- a/ext/dbase/package.xml
+++ b/ext/dbase/package.xml
@@ -30,7 +30,7 @@ are kept until you call dbase_pack().
<version>5.0rc1</version>
<date>2004-03-19</date>
<notes>
-package.xml added to support intallation using pear installer
+package.xml added to support installation using pear installer
</notes>
<filelist>
<file role="doc" name="CREDITS"/>
diff --git a/ext/dbase/php_dbase.h b/ext/dbase/php_dbase.h
index 4b7c12d3d..0fd8ef707 100644
--- a/ext/dbase/php_dbase.h
+++ b/ext/dbase/php_dbase.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2006 The PHP Group |
+ | Copyright (c) 1997-2007 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_dbase.h,v 1.15.2.1 2006/01/01 12:50:05 sniper Exp $ */
+/* $Id: php_dbase.h,v 1.15.2.1.2.1 2007/01/01 09:36:00 sebastian Exp $ */
#ifndef PHP_DBASE_H
#define PHP_DBASE_H
diff --git a/ext/dbase/tests/001.phpt b/ext/dbase/tests/001.phpt
index 51a448870..7c10efb26 100644
--- a/ext/dbase/tests/001.phpt
+++ b/ext/dbase/tests/001.phpt
@@ -51,7 +51,9 @@ int(%d)
Warning: dbase_create(): expected field name as first element of list in field 0 in %s on line %d
bool(false)
-int(%d)
+
+Warning: dbase_create(): Unable to create database without fields in %s on line %d
+bool(false)
Warning: dbase_create(): Expected array as second parameter in %s on line %d
bool(false)
diff --git a/ext/dbase/tests/002.phpt b/ext/dbase/tests/002.phpt
index 5c866443f..d5dd5c9e0 100644
--- a/ext/dbase/tests/002.phpt
+++ b/ext/dbase/tests/002.phpt
@@ -38,7 +38,7 @@ echo "Done\n";
Warning: dbase_open(): Invalid access mode -1 in %s on line %d
bool(false)
-Warning: dbase_open(): unable to open database %s in %s on line %d
+Warning: dbase_open(): Invalid access mode 1000 in %s on line %d
bool(false)
Warning: dbase_open(): unable to open database %s in %s on line %d
@@ -47,7 +47,7 @@ bool(false)
Warning: dbase_open(): unable to open database %s in %s on line %d
bool(false)
-Warning: dbase_open(): unable to open database in %s on line %d
+Warning: dbase_open(): The filename cannot be empty. in %s on line %d
bool(false)
int(%d)
int(%d)