Skip to content

Conversation

@ezaquarii
Copy link
Contributor

Log.d does not handle null, causing NPE thrown from
native logger implementation. This defensive check
ensures that legacy clients don't crash the system.

Signed-off-by: Chris Narkiewicz hello@ezaquarii.com

Log.d does not handle null, causing NPE thrown from
native logger implementation. This defensive check
ensures that legacy clients don't crash the system.

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
@ezaquarii ezaquarii force-pushed the ezaquarii/defensive-check-of-log-oc-arguments-for-null branch from dedff7b to ff1dae8 Compare September 23, 2019 18:58
@ezaquarii
Copy link
Contributor Author

This fixes all issues similar to this one once and for all:
nextcloud/android#4542

@nextcloud-android-bot
Copy link
Collaborator

Lint

TypemasterPR
Warnings00
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings15
Correctness Warnings39
Internationalization Warnings6
Malicious code vulnerability Warnings7
Multithreaded correctness Warnings3
Performance Warnings17
Security Warnings17
Dodgy code Warnings59
Total163

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings15
Correctness Warnings39
Internationalization Warnings6
Malicious code vulnerability Warnings7
Multithreaded correctness Warnings3
Performance Warnings17
Security Warnings17
Dodgy code Warnings59
Total163

@ezaquarii
Copy link
Contributor Author

This PR does not need a client change.

@codecov
Copy link

codecov bot commented Sep 23, 2019

Codecov Report

Merging #338 into master will decrease coverage by 0.04%.
The diff coverage is 23.07%.

@@            Coverage Diff            @@
##           master    #338      +/-   ##
=========================================
- Coverage   25.15%   25.1%   -0.05%     
=========================================
  Files         120     120              
  Lines        5267    5277      +10     
  Branches      695     703       +8     
=========================================
  Hits         1325    1325              
- Misses       3782    3789       +7     
- Partials      160     163       +3
Impacted Files Coverage Δ
.../com/owncloud/android/lib/common/utils/Log_OC.java 14.86% <23.07%> (-1.08%) ⬇️

if (tag != null && message != null && e != null) {
Log.d(tag, message, e);
StackTraceElement[] trace = e.getStackTrace();
appendLog(tag + ": " + message + " Exception: " + Arrays.toString(trace));
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you separated this? Could also still be inline, or?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean my "separation" vs "inline"?

Copy link
Contributor Author

@ezaquarii ezaquarii Sep 27, 2019

Choose a reason for hiding this comment

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

The logger implementation in Log_OC was extracted so we can use new logger implementation without re-writing the world. The application swaps this implementation for it's own Logger just after start, but the legacy code (other apps?) can still use the old implementation.

nextcloud/android#4275

I suspect that something tried to log before the logger implementation was swapped, and it wrote null causing an NPE.

Copy link
Member

Choose a reason for hiding this comment

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

Previously it was:
Arrays.toString(e.getStackTrace()))

now it is:
StackTraceElement[] trace = e.getStackTrace();
Arrays.toString(trace)

if (tag != null && message != null && t != null) {
Log.e(tag, message, t);
StackTraceElement[] trace = t.getStackTrace();
appendLog(tag + ": " + message + " Exception: " + Arrays.toString(trace));
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@tobiasKaminsky
Copy link
Member

@ezaquarii thanks again for your PR and finding the cause of the problem 🎉
I have just one question and then we can merge it.

@ezaquarii
Copy link
Contributor Author

ezaquarii commented Sep 27, 2019 via email

@tobiasKaminsky tobiasKaminsky merged commit 536702d into master Sep 27, 2019
@delete-merged-branch delete-merged-branch bot deleted the ezaquarii/defensive-check-of-log-oc-arguments-for-null branch September 27, 2019 07:30
@AndyScherzinger AndyScherzinger added this to the NC Android lib 1.7.0 milestone Sep 27, 2019
@tobiasKaminsky
Copy link
Member

/backport to stable-1.6

@backportbot-nextcloud
Copy link

backport to stable-1.6 in #341

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants