php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26355 [PATCH] flock() doesn't initialize the wouldblock argument
Submitted: 2003-11-21 16:03 UTC Modified: 2003-11-23 20:41 UTC
From: mlemos at acm dot org Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.3.4 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mlemos at acm dot org
New email:
PHP Version: OS:

 

 [2003-11-21 16:03 UTC] mlemos at acm dot org
Description:
------------
flock() does not initialize the wouldblock argument when present and it succeeds locking, even when non-blocking locking is requested.

It is also failing when wouldblock argument is not present but  non blocking locking is requested and flock() system call returns EWOULDBLOCK. This is a minor issue.

This patch should fix both issues:

*** ext/standard/file.c 2003-11-21 18:39:13.000000000 -0200
--- ext/standard/file.c.fixed   2003-11-21 18:39:00.000000000 -0200
***************
*** 251,261 ****
           if (arg2 & 4) we won't block on the lock */
        act = flock_values[act - 1] | (Z_LVAL_PP(arg2) & 4 ? LOCK_NB : 0);
        if (flock(fd, act)) {
!               if (errno == EWOULDBLOCK && arg_count == 3) {
!                       ZVAL_LONG(*arg3, 1);
                } else {
                        RETURN_FALSE;
!               }
        }
        RETURN_TRUE;
  }
--- 251,269 ----
           if (arg2 & 4) we won't block on the lock */
        act = flock_values[act - 1] | (Z_LVAL_PP(arg2) & 4 ? LOCK_NB : 0);
        if (flock(fd, act)) {
!               if ((Z_LVAL_PP(arg2) & 4) && errno == EWOULDBLOCK) {
!                       if(arg_count == 3) {
!                               ZVAL_LONG(*arg3, 1);
!                       }
                } else {
                        RETURN_FALSE;
!               }
!       }
!       else
!       {
!               if(arg_count == 3) {
!                       ZVAL_LONG(*arg3, 0);
!               }
        }
        RETURN_TRUE;
  }


Reproduce code:
---------------
<?php
 
        if(!($file=(fopen("testfile","w")))) die("could not open file");
        if(flock($file,6,&$wouldblock))
                echo "flock succeed, wouldblock ",serialize($wouldblock),"\n";
        else
                echo "flock failed\n";
        fclose($file);
?>

Expected result:
----------------
flock succeed, wouldblock i:0;

Actual result:
--------------
flock succeed, wouldblock N;

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-21 21:21 UTC] sniper@php.net
Provide the patches always in unified format.
(diff -u)

And provide an url pointing to the patch file, DO NOT add these to bug reports.

 [2003-11-21 22:19 UTC] mlemos at acm dot org
Ok, here it is:

http://manuellemos.sites.uol.com.br/file.c.patch
 [2003-11-23 20:41 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, 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/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 08:01:30 2024 UTC