Skip to content

TF1/TString possible overflow fix + Warning in TString#8426

Merged
Axel-Naumann merged 2 commits intoroot-project:masterfrom
AdvaitDhingra:tf1-issue
Jun 18, 2021
Merged

TF1/TString possible overflow fix + Warning in TString#8426
Axel-Naumann merged 2 commits intoroot-project:masterfrom
AdvaitDhingra:tf1-issue

Conversation

@AdvaitDhingra
Copy link
Copy Markdown
Contributor

I have tried to fix this issue.

This should prevent a possible overflow in TF1, as now the min of the length of strlen(formula) and 5 is taken, therefore preventing a possible overflow.

Also in TString if the first n characters of cs conatin \0 it warns you.

@phsft-bot
Copy link
Copy Markdown

Can one of the admins verify this patch?

@AdvaitDhingra AdvaitDhingra force-pushed the tf1-issue branch 4 times, most recently from 1b529b2 to b3aa3b1 Compare June 14, 2021 19:32
@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

I somehow managed to mess up the commits in multiple of my PR's. Sorry for the inconvenience.

const auto formulaLength = strlen(formula);
// First check if we are making a convolution
if (TString(formula, 5) == "CONV(" && formula[strlen(formula) - 1] == ')') {
if (TString(formula, 5) == "CONV(" && formula[formulaLength - 1] == ')') {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here you also need the strncmp trick, because that's the line that triggered the error that started all this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Look up "git interactive rebase". You can use it to fix the existing commits (git commit --fixup xxxx), and you can also remove the "Added some constants" "Revert Added some constants" while rebasing.
Once you get the hang of it, you will love it!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, I forgot that. I will change it as soon as I'm home

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ahh thanks for the interactive rebase tip. I was looking for something like that 😀

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

AdvaitDhingra commented Jun 15, 2021

Ah, there we go. git rebase -i HEAD~4 worked. Thanks @hageboeck :D

Copy link
Copy Markdown
Member

@hageboeck hageboeck left a comment

Choose a reason for hiding this comment

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

Now that you know how to rebase, could you edit the commit messages, please?
(git rebase -i origin/master) and then use e to edit the messages.

  • Use a short title, max 80 characters, e.g. "Add warning in TString constructor"
  • Then, after an empty line, explain in detail what you did and why. E.g. "Warn when a TString of a fixed length is constructed from an input string that's too short."

Like this, it will be easy to understand what happened when people are looking into these commits at some point in the future.

For the TF1 fix, explain what the bug was. Edit: And mention something like Fix #8136 in the commit message.

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

Now that you know how to rebase, could you edit the commit messages, please?
(git rebase -i origin/master) and then use e to edit the messages.

  • Use a short title, max 80 characters, e.g. "Add warning in TString constructor"
  • Then, after an empty line, explain in detail what you did and why. E.g. "Warn when a TString of a fixed length is constructed from an input string that's too short."

Like this, it will be easy to understand what happened when people are looking into these commits at some point in the future.

For the TF1 fix, explain what the bug was. Edit: And mention something like Fix #8136 in the commit message.

Okay. I will change it

@AdvaitDhingra AdvaitDhingra force-pushed the tf1-issue branch 2 times, most recently from 51ee9a6 to 6cd4ca7 Compare June 16, 2021 13:51
@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

Are these commit names better?

@hageboeck
Copy link
Copy Markdown
Member

Are these commit names better?

A bit, but look at this commit for example:
6ddcc0d

You can use the message to explain a bit better what was going on e.g.:

[TF1] Fix buffer overflow.

TF1 was copying 5 characters from an incoming string without checking its length.
This was replaced by strncmp, which takes into account the length.

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

Are these commit names better?

A bit, but look at this commit for example:
6ddcc0d

You can use the message to explain a bit better what was going on e.g.:

[TF1] Fix buffer overflow.

TF1 was copying 5 characters from an incoming string without checking its length.
This was replaced by strncmp, which takes into account the length.

So in the interactive rebase I just write this detailed description under the commit? Because when I do that it tells me that that line is invalid. Do I need to use some special indentation?

@hageboeck
Copy link
Copy Markdown
Member

Are these commit names better?

A bit, but look at this commit for example:
6ddcc0d
You can use the message to explain a bit better what was going on e.g.:

[TF1] Fix buffer overflow.

TF1 was copying 5 characters from an incoming string without checking its length.
This was replaced by strncmp, which takes into account the length.

So in the interactive rebase I just write this detailed description under the commit? Because when I do that it tells me that that line is invalid. Do I need to use some special indentation?

Ah, no! That's r for "reword". git will stop and let you edit the commit message. :-)

The user now gets a warning in the TString::TString constructor if the input string is shorter than the requested size.
@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

I think I got it. Thank you @hageboeck for all of the help :D

@hageboeck
Copy link
Copy Markdown
Member

Very nice! Interactive rebase is awesome once you learn how to use it! 👏

@hageboeck
Copy link
Copy Markdown
Member

@phsft-bot build

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

Very nice! Interactive rebase is awesome once you learn how to use it!

Yeah, it is. Feels like I've been living under a rock hehe

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-performance-centos8-multicore/default.
Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build
See console output.

Warnings:

  • [2021-06-16T14:38:59.129Z] /data/sftnight/workspace/root-pullrequests-build/root/core/base/src/TString.cxx:134:19: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘Ssiz_t’ {aka ‘int’} [-Wsign-compare]

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-ubuntu16/nortcxxmod.
Running on sft-ubuntu-1604-1.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Warnings:

  • [2021-06-16T14:41:17.945Z] /mnt/build/workspace/root-pullrequests-build/root/core/base/src/TString.cxx:134:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

Are these warnings critical? Is there something I can do?

@Axel-Naumann
Copy link
Copy Markdown
Member

Axel-Naumann commented Jun 16, 2021

Yes they need to be fixed. I could tell you - but what I'd recommend (look, we're teaching you here :-) ) is to copy the warning text, search the Internet, and pick the most helpful posting on StackOverflow: that'll explain you what to do. And it's a key pattern to become a successful developer, it's how all of us fix our warnings 🤣

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

Yes they need to be fixed. I could tell you - but what I'd recommend (look, we're teaching you here :-) ) is to copy the warning text, search the Internet, and pick the most helpful posting on StackOverflow: that'll explain you what to do. And it's a key pattern to become a successful developer, it's how all of us fix our warnings

Ahh hehe. Okay, I'll try to fix it :D . Thanks for the learning opportunity

@phsft-bot
Copy link
Copy Markdown

Build failed on mac11.0/cxx17.
Running on macphsft20.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Warnings:

  • [2021-06-16T14:59:31.970Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/core/base/src/TString.cxx:134:19: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'Ssiz_t' (aka 'int') [-Wsign-compare]

@phsft-bot
Copy link
Copy Markdown

Build failed on mac1014/python3.
Running on macitois21.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Warnings:

  • [2021-06-16T15:20:46.897Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/core/base/src/TString.cxx:134:19: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'Ssiz_t' (aka 'int') [-Wsign-compare]

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

That should take care of that

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-06-16T17:48:56.047Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/base/src/TString.cxx:134:31: error: expected ‘;’ before ‘{’ token
  • [2021-06-16T17:48:56.047Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/base/src/TString.cxx:137:27: error: expected ‘)’ before ‘;’ token
  • [2021-06-16T17:48:56.047Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/base/src/TString.cxx:138:11: error: ‘data’ was not declared in this scope

Warnings:

  • [2021-06-16T17:48:56.047Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/base/src/TString.cxx:134:8: warning: init-statement in selection statements only available with -std=c++17 or -std=gnu++17
  • [2021-06-16T17:48:56.047Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/base/src/TString.cxx:134:19: warning: statement has no effect [-Wunused-value]
  • [2021-06-16T17:48:56.047Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/base/src/TString.cxx:137:27: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]
  • [2021-06-16T17:48:56.047Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/base/src/TString.cxx:137:10: warning: unused variable ‘data’ [-Wunused-variable]

@hageboeck
Copy link
Copy Markdown
Member

@phsft-bot build

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

Copy link
Copy Markdown
Member

@Axel-Naumann Axel-Naumann left a comment

Choose a reason for hiding this comment

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

Please correct the whitespace issue. LGTM otherwise!

@Axel-Naumann
Copy link
Copy Markdown
Member

Can you squash all commits but "Added Warning to TString constuctor" into one, such that this branch ends up having two commits? You can do that with interactive rebase, making all commits after the second (!) as "fixup", such that they just modify / update the second commit.

@AdvaitDhingra AdvaitDhingra force-pushed the tf1-issue branch 4 times, most recently from 3750978 to 435f546 Compare June 17, 2021 12:40
The length of formula is now chached and reused. Furthermore strncmp is used instead of TString for preformance reasons.
@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

That should be all there is to format. At least according to clang-format

@hageboeck
Copy link
Copy Markdown
Member

@phsft-bot build

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@hageboeck
Copy link
Copy Markdown
Member

Looks good to me, let's wait for the build!

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

I think the builds were successful

@hageboeck
Copy link
Copy Markdown
Member

I think the builds were successful

Yes, they were. Yesterday, when you wrote this message, Jenkins (the most important step) was still running.
Well done, thanks!

@hageboeck
Copy link
Copy Markdown
Member

@Axel-Naumann please merge.

@Axel-Naumann Axel-Naumann merged commit a9d2405 into root-project:master Jun 18, 2021
@AdvaitDhingra AdvaitDhingra deleted the tf1-issue branch June 18, 2021 18:15
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.

Possible buffer overflow in TF1 / TString

6 participants