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

Check the return value of getUserSession before using it #30418

Merged
merged 1 commit into from
Feb 9, 2018

Conversation

sharidas
Copy link
Contributor

@sharidas sharidas commented Feb 8, 2018

Checking if the value returned by getUserSession
and getUser is null or not before using it.

Signed-off-by: Sujith H sharidasan@owncloud.com

Description

There were situations where userSession was directly calling getUser which returned null and the return value was never checked. Another case was getUserSession was returning null. Hence getUser was called on null. This caused breaking the code flow under certain conditions. This change is to fix the assumptions made.

Related Issue

#30335
#30416

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@sharidas sharidas self-assigned this Feb 8, 2018
@PVince81
Copy link
Contributor

PVince81 commented Feb 8, 2018

Please add unit tests there

Checking if the value returned by getUserSession
and getUser is null or not before using it.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
@codecov
Copy link

codecov bot commented Feb 8, 2018

Codecov Report

Merging #30418 into master will increase coverage by <.01%.
The diff coverage is 91.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #30418      +/-   ##
============================================
+ Coverage     60.87%   60.88%   +<.01%     
- Complexity    18568    18572       +4     
============================================
  Files          1093     1093              
  Lines         61325    61329       +4     
============================================
+ Hits          37333    37339       +6     
+ Misses        23992    23990       -2
Impacted Files Coverage Δ Complexity Δ
lib/private/User/User.php 83.72% <100%> (+0.19%) 67 <0> (+3) ⬆️
lib/private/Log.php 79.51% <83.33%> (+2.97%) 37 <0> (+1) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9a6ec7d...9a1b527. Read the comment docs.

@sharidas
Copy link
Contributor Author

sharidas commented Feb 8, 2018

Updated with unit tests.

@PVince81
Copy link
Contributor

PVince81 commented Feb 8, 2018

Thanks. Is there also a positive test for when log conditions are set and a user is present ?

@sharidas
Copy link
Contributor Author

sharidas commented Feb 8, 2018

Thanks. Is there also a positive test for when log conditions are set and a user is present ?

Yes the positive tests are already there.

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

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

👍

@PVince81 PVince81 added this to the development milestone Feb 8, 2018
@sharidas sharidas merged commit 72c168b into master Feb 9, 2018
@sharidas sharidas deleted the check-getusersession branch February 9, 2018 06:17
@phil-davis
Copy link
Contributor

I guess this needs to be backported?

@sharidas
Copy link
Contributor Author

sharidas commented Feb 9, 2018

Creating backport PR.

@sharidas
Copy link
Contributor Author

sharidas commented Feb 9, 2018

Backport PR: #30432

@lock
Copy link

lock bot commented Aug 1, 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 1, 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.

None yet

3 participants