php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49125 Error in dba_exists C code
Submitted: 2009-07-31 20:56 UTC Modified: 2009-08-02 00:24 UTC
From: jdornan at stanford dot edu Assigned:
Status: Closed Package: DBM/DBA related
PHP Version: 5.2.10 OS: *
Private report: No CVE-ID:
 [2009-07-31 20:56 UTC] jdornan at stanford dot edu
Description:
------------
Using dba_exists with a file opened with dba_popen and the db4 handler will result in an error.

Notice: dba_exists(): DB_THREAD mandates memory allocation flag on DBT data

I found a similar problem was reported before for dba_fetch. Since dba_fetch and dba_exists share common code it was clear to see how this error could be fixed. Here is a simple diff between the original file and the fixed version.

*** dba_db4.c 2009-07-31 13:24:14.000000000 -0400
--- dba_db4.c.fixed 2009-07-31 13:27:49.000000000 -0400
***************
*** 175,181 ****
--- 175,187 ----
  DB4_GKEY;
  
  memset(&gval, 0, sizeof(gval));
+ if (info->flags & DBA_PERSISTENT) {
+ gval.flags |= DB_DBT_MALLOC;
+ }
  if (!dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) {
+ if (info->flags & DBA_PERSISTENT) {
+ free(gval.data);
+ }
  return SUCCESS;
  }
  return FAILURE;

I checked an the error still exists in the 5.2 snapshot.


Reproduce code:
---------------
Test #1

<?PHP
$db = dba_popen('test.db4', 'c', 'db4');

dba_insert('b0rk', 'b0rk', $db);

if (dba_exists('b0rk', $db) == true) {
    echo 'Yes, we have b0rk!' . PHP_EOL;
}
?>

Test #2

<?PHP
error_reporting(E_ALL);

$db = dba_popen('test.db4', 'c', 'db4');

dba_insert('b0rk', 'b0rk', $db);

if (dba_exists('b0rk', $db) == true) {
    echo 'Yes, we have b0rk!' . PHP_EOL;
}
?>


Expected result:
----------------
Yes, we have b0rk!

Actual result:
--------------
Test #1

Nothing.

Test #2

Notice: dba_exists(): DB_THREAD mandates memory allocation flag on DBT data in /tmp/test2.php on line 8

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-01 23:10 UTC] svn@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=286636
Log: - Fixed bug #49125 (Error in dba_exists C code)
  patch by: jdornan at stanford dot edu
 [2009-08-02 00:24 UTC] jani@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 06:02:13 2014 UTC