helly Sun Dec 14 17:08:19 2003 EDT
Modified files:
/php-src/ext/dba dba.c dba_flatfile.c
Log:
- Fix Bug #26304 Unexpected data loss when opening dba file
- Correct handling for flatfile handler
Index: php-src/ext/dba/dba.c
diff -u php-src/ext/dba/dba.c:1.105 php-src/ext/dba/dba.c:1.106
--- php-src/ext/dba/dba.c:1.105 Sat Dec 13 10:00:04 2003
+++ php-src/ext/dba/dba.c Sun Dec 14 17:08:18 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dba.c,v 1.105 2003/12/13 15:00:04 helly Exp $ */
+/* $Id: dba.c,v 1.106 2003/12/14 22:08:18 helly Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -648,15 +648,23 @@
case 'c':
modenr = DBA_CREAT;
lock_mode = (lock_flag & DBA_LOCK_CREAT) ? LOCK_EX : 0;
- if (!lock_mode || !lock_dbf) {
- file_mode = "a+b";
+ if (lock_mode) {
+ if (lock_dbf) {
+ /* the create/append check will be done on the
lock
+ * when the lib opens the file it is already
created
+ */
+ file_mode = "r+b"; /* read & write, seek
0 */
+ lock_file_mode = "a+b"; /* append */
+ } else {
+ file_mode = "a+b"; /* append */
+ lock_file_mode = "w+b"; /* create/truncate */
+ }
} else {
- /* the create/append check will be done on the lock
- * when the lib opens the file it is already created
- */
- file_mode = "w+b";
- lock_file_mode = "a+b";
+ file_mode = "a+b";
}
+ /* In case of the 'a+b' append mode, the handler is
responsible
+ * to handle any rewind problems (see flatfile handler).
+ */
break;
case 'n':
modenr = DBA_TRUNC;
Index: php-src/ext/dba/dba_flatfile.c
diff -u php-src/ext/dba/dba_flatfile.c:1.13 php-src/ext/dba/dba_flatfile.c:1.14
--- php-src/ext/dba/dba_flatfile.c:1.13 Tue Jun 10 16:03:26 2003
+++ php-src/ext/dba/dba_flatfile.c Sun Dec 14 17:08:18 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dba_flatfile.c,v 1.13 2003/06/10 20:03:26 imajes Exp $ */
+/* $Id: dba_flatfile.c,v 1.14 2003/12/14 22:08:18 helly Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -41,6 +41,17 @@
DBA_OPEN_FUNC(flatfile)
{
+ int fd, flags;
+
+ if (info->mode != DBA_READER) {
+ if (SUCCESS != php_stream_cast(info->fp, PHP_STREAM_AS_FD, (void*)&fd,
1)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not cast
stream");
+ return FAILURE;
+ }
+ flags = fcntl(fd, F_SETFL);
+ fcntl(fd, F_SETFL, flags & ~O_APPEND);
+ }
+
info->dbf = pemalloc(sizeof(flatfile), info->flags&DBA_PERSISTENT);
memset(info->dbf, 0, sizeof(flatfile));
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php