Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: Error PHP Array to string conversion at .../oc/lib/private/template/functions.php#36 #18921

Closed
wants to merge 1 commit into from

Conversation

zyrill
Copy link

@zyrill zyrill commented Sep 9, 2015

See #17468 for bug description.

@scrutinizer-notifier
Copy link

A new inspection was created.

@@ -33,7 +33,7 @@
* @param string|array $string the string which will be escaped and printed
*/
function p($string) {
print(OC_Util::sanitizeHTML($string));
implode(print(OC_Util::sanitizeHTML($string)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be print(implode( ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like:

if(is_array($string)) {
   $string = implode($string);
}
print(OC_Util::sanitizeHTML($string));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to @MorrisJobke 's improvement, otherwise implode() will eat the input string and return null.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like it. 👍 :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print(implode( doesn't work by the way. don't do it! will break everything... end of the world stuff. you know, hellfire raining from the skies. think sulfur burning. or that fat guy after having a lot of onions...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zyrill Can you fix your PR with the suggested improvements?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will. I'm in a meeting now, give me a few hours.

@zyrill
Copy link
Author

zyrill commented Sep 15, 2015

@MorrisJobke anything else I need to do? I'm rather new to the github experience...

@DeepDiver1975 DeepDiver1975 added this to the 9.0-next milestone Sep 15, 2015
@szepeviktor
Copy link
Contributor

👍

@szepeviktor
Copy link
Contributor

sanitizeHTML() is prepared for an array.

function p($string) {
    $sanitized = OC_Util::sanitizeHTML($string);
    if (is_array($sanitized)) {
        $sanitized = implode($sanitized);
    }
    print $sanitized;
 }

if (is_array($sanitized)) {
$sanitized = implode($sanitized);
}
print $sanitized;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for nitpicking: can you please add brackets after print? For coding guidelines compliance ;)

Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was the one who left it out. Sorry.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just applied this to 8.1.3 and it doesn't work!

Get an error message:

Error occurred while checking server setup

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just applied this to 8.1.3 and it doesn't work!

It is still in development.

@widac
Copy link

widac commented Sep 28, 2015

Hello, I am not familar with how this works on this page.

I just want to say I've tested this to 8.1.3 and this code works for me

function p($string) {
        $sanitized = OC_Util::sanitizeHTML($string);  
 if (is_array($sanitized)) {  
        $sanitized = implode($sanitized);  
    }  
    print ($sanitized);  

Thanks.

@ronniehd
Copy link

ronniehd commented Oct 5, 2015

The above fix by @widac doesn't work for me on 8.1.3, i got blank page accessing to owncloud webui after that.
Reverting back to:

function p($string) {
    print(OC_Util::sanitizeHTML($string));
}

@zyrill
Copy link
Author

zyrill commented Oct 6, 2015

Alright, got the brackets in. Any more comments?

@MorrisJobke
Copy link
Contributor

Alright, got the brackets in. Any more comments?

Can we get the 11 commits squashed into 1 because it only changes 5 lines. ;)

Then I think this is fine for review. If you need help by juggling with git feel free to ping me in IRC (#owncloud-dev on freenode)

@szepeviktor
Copy link
Contributor

git reset HEAD~11

@zyrill zyrill closed this Oct 6, 2015
@MorrisJobke MorrisJobke reopened this Oct 6, 2015
…wncloud/lib/private/template/functions.php#36

See #17468 for bug description.
Incorporated changes proposed by @MorrisJobke and by @szepeviktor, see #18921
@szepeviktor
Copy link
Contributor

:hurray:

@zyrill
Copy link
Author

zyrill commented Oct 6, 2015

Puh, wär hätte gedacht, dass squashen so schwierig ist. Danke, @MorrisJobke. :)

@MorrisJobke
Copy link
Contributor

@zyrill Because you asked about CI - I created a local branch and PR to trigger CI: #19612

@DeepDiver1975 We need to focus on CI for forks after the release ;)

@PVince81
Copy link
Contributor

@LukasReschke what do you think ?

@LukasReschke
Copy link
Member

Fair enough from my PoV. Though I'd vote only for master and no backport.

@mmattel
Copy link
Contributor

mmattel commented Oct 27, 2015

Any update on this? I also got this error on a fresh install on stable 8.2

@EtienneBruines
Copy link

The checks are failing; that's not good.

But I'm here to confirm that it (=changing that 1 function) did fix the error I had on fresh install (stable 8.2.0).

@MorrisJobke
Copy link
Contributor

@nickvergessen @PVince81 @LukasReschke Lets get this in :)

@MorrisJobke
Copy link
Contributor

Please review ;)

@mmattel
Copy link
Contributor

mmattel commented Oct 27, 2015

👍 I tested on stable 8.2 and the error did not raise again

@nickvergessen
Copy link
Contributor

I'm not sure, when it's an array it still fails to implode.
So my suggestion would be to throw a real error when it is called with an array?

@szepeviktor
Copy link
Contributor

@MorrisJobke
Copy link
Contributor

It is meant to be called with an array:
https://github.com/zyrill/core/blob/master/lib/private/template/functions.php#L33

This is the weird thing ... The problem here is that it is kind of public API ... cc @DeepDiver1975

@MorrisJobke
Copy link
Contributor

This is the weird thing ... The problem here is that it is kind of public API ... cc @DeepDiver1975

Should we change the PHPDoc - it doesn't work before anyways.

@zyrill
Copy link
Author

zyrill commented Oct 27, 2015

Anything needed that I can help with?

@MorrisJobke
Copy link
Contributor

Anything needed that I can help with?

We first need a consensus ;)

@PVince81
Copy link
Contributor

Do we actually know where the original error comes from ? Which template/app is calling this function with an array ?

@MorrisJobke
Copy link
Contributor

Do we actually know where the original error comes from ? Which template/app is calling this function with an array ?

I activated contacts and calendar. Both don't throw the error on the admin page anymore.

I guess we should simply fix the PHPDoc to only accept string and then fix malicious usage of p() with an array as parameter. Otherwise we will get into the "black magic coding" again. @PVince81 @nickvergessen Opinions on this?

@nickvergessen
Copy link
Contributor

yes, agreeed

@MorrisJobke
Copy link
Contributor

yes, agreeed

#20679

@MorrisJobke
Copy link
Contributor

Sorry for saying this: We will close this here and need to check where this method is called in the wrong way.

If you have still this problem it would be nice to get a stack trace or at least all installed apps including their versions.

Thanks

@bcutter
Copy link

bcutter commented Aug 15, 2016

Hi, this is definitely not fixed. I need to manually apply the fix in functions.php now since 2015-11-19 after every single Owncloud update.

sudo -u www-data php /var/www/owncloud/occ status
  - installed: true
  - version: 9.0.4.1
  - versionstring: 9.0.4
  - edition:

sudo -u www-data php /var/www/owncloud/occ app:list
Enabled:
  - activity: 2.2.1
  - calendar: 1.3.2
  - comments: 0.2
  - contacts: 1.3.1.0
  - dav: 0.1.6
  - direct_menu: 0.8.1
  - documents: 0.12.1
  - federatedfilesharing: 0.1.0
  - federation: 0.0.4
  - files: 1.4.4
  - files_external: 0.5.2
  - files_locking: true
  - files_pdfviewer: 0.8.1
  - files_share_qr: 0.1
  - files_sharing: 0.9.1
  - files_texteditor: 2.1
  - files_trashbin: 0.8.0
  - files_versions: 1.2.0
  - files_videoplayer: 0.9.8
  - files_videoviewer: 0.1.3
  - firstrunwizard: 1.1
  - gallery: 14.5.0
  - logreader: 1.1.5
  - notifications: 0.2.3
  - ownbackup: 0.3.8
  - provisioning_api: 0.3.0
  - systemtags: 0.2
  - templateeditor: 0.1
  - updatenotification: 0.1.0
Disabled:
  - encryption
  - external
  - ocusagecharts
  - storagecharts2
  - storagecharts2_new
  - updater
  - user_external
  - user_ldap
  - user_otp
  - user_webdavauth

@lock
Copy link

lock bot commented Aug 5, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.