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

Replace banned APIs with safe ones #1056

Merged
merged 4 commits into from
Mar 19, 2019
Merged

Replace banned APIs with safe ones #1056

merged 4 commits into from
Mar 19, 2019

Conversation

ffried
Copy link
Member

@ffried ffried commented Mar 19, 2019

New Pull Request Checklist

  • I have read and understood the CONTRIBUTING guide

  • I have read the Documentation

  • I have searched for a similar pull request in the project and found none

  • I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

  • I have added the required tests to prove the fix/feature I am adding

  • I have updated the documentation (if necessary)

  • I have run the tests and they pass

  • I have run the lint and it passes (pod lib lint)

This merge request fixes / refers to the following issues: #1050

Pull Request Description

This replaces the banned APIs in the list mentioned in #1050 with their safe counterparts.

@lolgear
Copy link
Contributor

lolgear commented Mar 19, 2019

@ffried
Could you merge #1054 first? ( If it is necessary ).

@ffried
Copy link
Member Author

ffried commented Mar 19, 2019

@lolgear done

@lolgear
Copy link
Contributor

lolgear commented Mar 19, 2019

I neither like 1 as a length of desired string nor 2 as a max length of string in strnlen.
Maybe it is better to use macros here or const/static?
I don't know, it is weird :/

@ffried
Copy link
Member Author

ffried commented Mar 19, 2019

What's wrong with these values? 1 as length is simply malloc(size * 1). And since strnlen will have to check for \0 in the string, 2 as max len will make sure it doesn't look too far but gives up whenever the string is any longer than 1. Since this is an arbitrary choice, I've added the comment there.

The first is just "normal" IMHO. The second is arbitrary, but only for this specific location, so macros or static const won't do any good either. That's what comments are for.

@OSSPolice
Copy link

1 Warning
⚠️ The library files were changed, but the tests remained unmodified. Consider updating or adding to the tests to match the library changes.

Generated by 🚫 Danger

@codecov-io
Copy link

codecov-io commented Mar 19, 2019

Codecov Report

Merging #1056 into master will decrease coverage by 0.78%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1056      +/-   ##
==========================================
- Coverage   39.65%   38.87%   -0.79%     
==========================================
  Files          27       27              
  Lines        4017     4018       +1     
==========================================
- Hits         1593     1562      -31     
- Misses       2424     2456      +32
Impacted Files Coverage Δ
Classes/DDLog.m 59.15% <0%> (ø) ⬆️
Classes/DDTTYLogger.m 0% <0%> (ø) ⬆️
Classes/Extensions/DDFileLogger+Buffering.m 79.16% <100%> (+0.21%) ⬆️
Classes/DDASLLogger.m 13.46% <0%> (-42.31%) ⬇️
Classes/DDOSLogger.m 57.69% <0%> (-19.24%) ⬇️

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 168419e...25b5649. Read the comment docs.

@lolgear
Copy link
Contributor

lolgear commented Mar 19, 2019

@ffried
Fine, right.

I think about "pure" solution here.

  1. Check first symbol of string to not to be null.
  2. Check first symbol to be '/'.
  3. Check second symbol to be null.
// If I am correct about comparison here. Not Sure
if (name != '\0' && name == '/' && *(++name) == '\0') {}

Copy link
Contributor

@lolgear lolgear left a comment

Choose a reason for hiding this comment

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

Vanishing dust in C runtime - Nice blow!

@lolgear
Copy link
Contributor

lolgear commented Mar 19, 2019

@ffried
Ah!
I see, you calloc 1s instead of sizeof(char) :)

@ffried
Copy link
Member Author

ffried commented Mar 19, 2019

@lolgear You're actually right. We could express these as (char *)calloc(_appLen + 1, sizeof(char))... That sounds better indeed. Let's change that.

@lolgear
Copy link
Contributor

lolgear commented Mar 19, 2019

@ffried
What about C pointer arithmetics?
Do you admire it? :)

@ffried
Copy link
Member Author

ffried commented Mar 19, 2019

@lolgear What about it? 🙂

@lolgear
Copy link
Contributor

lolgear commented Mar 19, 2019

@ffried

// If I am correct about comparison here. Not sure
if (name != '\0' && name == '/' && *(++name) == '\0') {}

@ffried
Copy link
Member Author

ffried commented Mar 19, 2019

@lolgear I think it would be correct. But from a readability perspective much worse than strnlen(name, 2) == 1 😉

@lolgear
Copy link
Contributor

lolgear commented Mar 19, 2019

@ffried
So, let's merge it?

@ffried
Copy link
Member Author

ffried commented Mar 19, 2019

@lolgear Fine by me. Let's wait for the CI 🙂

@sushichop
Copy link
Member

LGTM👍
Now I found another banned API(function). So I'll create a PR for it later.

@sushichop sushichop merged commit 5f6f590 into master Mar 19, 2019
@bpoplauschi bpoplauschi deleted the feature/evade_bans branch April 2, 2019 16:39
@bpoplauschi bpoplauschi added this to the 3.5.3 milestone Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants