Caucho Forums  

This forum is permanently closed because of spam. For free community support, please visit Google Groups:


Go Back   Caucho Forums > Quercus

Reply
 
Thread Tools Display Modes
  #1  
Old 02-01-2011, 12:25 PM
geleont geleont is offline
Junior Member
 
Join Date: Feb 2011
Posts: 1
Default [solved] file_get_contents BUG

file_get_contents in quercus 4.0.11 has bug.

Minimal code to reproduce:
<?php
file_put_contents("123", "Hello",LOCK_EX);
?>
Cause
java.lang.NullPointerException
com.caucho.quercus.lib.file.FileOutput.unlock(File Output.java:197)
com.caucho.quercus.lib.file.FileModule.flock(FileM odule.java:1087)
com.caucho.quercus.lib.file.FileModule.file_put_co ntents(FileModule.java:1045)
I reviewed source code of quercus FileModule module and I am sure it happens because we close os, which is linked on the same object as s(BinaryOutput os = (BinaryOutput) s and after that we trying to make
flock(env, (LockableStream) s, LOCK_UN, null);
on that stream.
public static Value file_put_contents(Env env,
StringValue filename,
Value data,
@Optional int flags,
@Optional Value context)
{
if (filename.length() == 0) {
env.warning(L.l("file name must not be null&quot);
return BooleanValue.FALSE;
}

// php/1634

BinaryStream s = null;

try {
boolean useIncludePath = (flags &; FILE_USE_INCLUDE_PATH) != 0;
String mode = (flags &; FILE_APPEND) != 0 ? "a" : "w";

s = fopen(env, filename, mode, useIncludePath, context);

if (! (s instanceof BinaryOutput))
return BooleanValue.FALSE;

if ((flags &; LOCK_EX) != 0) {
if (s instanceof LockableStream) {
if (! flock(env, (LockableStream) s, LOCK_EX, null))
return BooleanValue.FALSE;
} else {
return BooleanValue.FALSE;
}
}

BinaryOutput os = (BinaryOutput) s;

try {
long dataWritten = 0;

if (data instanceof ArrayValue) {
for (Value item : ((ArrayValue) data).values()) {
InputStream is = item.toInputStream();

dataWritten += os.write(is, Integer.MAX_VALUE);

is.close();
}
}
else {
InputStream is = data.toInputStream();

dataWritten += os.write(is, Integer.MAX_VALUE);

is.close();
}

return LongValue.create(dataWritten);
} finally {
os.close();
}
} catch (IOException e) {
throw new QuercusModuleException(e);
} finally {
if (s != null &;&; (s instanceof LockableStream)
&;&; ((flags &; LOCK_EX) != 0))
flock(env, (LockableStream) s, LOCK_UN, null);
}
}
Reply With Quote
  #2  
Old 02-02-2011, 10:12 AM
domdorn domdorn is offline
Administrator
 
Join Date: Dec 2009
Location: Vienna / Austria
Posts: 97
Default

thanks for adding it to the issue tracker.

http://bugs.caucho.com/view.php?id=4370
Reply With Quote
  #3  
Old 02-02-2011, 11:17 AM
domdorn domdorn is offline
Administrator
 
Join Date: Dec 2009
Location: Vienna / Austria
Posts: 97
Default

bug is fixed in current trunk.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:11 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.