-
Notifications
You must be signed in to change notification settings - Fork 662
Only rely on our own assert() #2473
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
Open
kinkie
wants to merge
6
commits into
squid-cache:master
Choose a base branch
from
kinkie:no-nodebug
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
10bdbe6
remove PURIFY and NODEBUG
kinkie a887576
compat/assert.h is only used in c++ code
kinkie 8d50e01
remove references to NDEBUG
kinkie c49c3b2
remove <cassert> references
kinkie 41bbc56
Also use compat/assert.h from C files
kinkie 956fa7a
no need to include compat/assert.g in debug/Stream.g
kinkie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,6 @@ | |
|
|
||
| #include "squid.h" | ||
|
|
||
| #if HAVE_ASSERT_H | ||
| #include <assert.h> | ||
| #endif | ||
|
|
||
| int | ||
| main(int argc, char *argv[]) | ||
| { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do need to still honor these
PURIFYandNODEBUGbuild environment expectations. Just add the#undefcondition above the existing#if PURIFYline.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also
#include <cassert>in this compat file before replacing the systemassertdefinition to ensure the appropriate file wrappers are defined to prevent re-include issues.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly disagree with a "need to honor" opinion and doubt that relevant "environment expectations" actually exist:
NODEBUGis a typo (the well-known macro is spelledNDEBUG). We do not need to honor typos, even if somebody is using them. I am not aware of any productionNODEBUGSquid use, and, more importantly, such use would result in a malfunctioning Squid because Squid makes essential calls wrapped inassert().PURIFYis a macro recognized by an ancient memory checker calledpurify. I could not find any signs of activepurifyor "purify plus" use today (for anything). Public documentation that I could find has not been updated since 2003, contains broken links, and resides on what looks like an "archived" or "forgotten" web site. Even if somebody is using that tool for Squid development today, Squid itself no longer has any non-assertion code that is conditioned on that macro, such macro-protected code did not even compile since before September 2006 (see commit 3a85184), and ignoring memory leaks/problems in assertion code is itself a bad idea if production code runs with assertions.This PR is valuable if it removes all
PURIFY,NDEBUG, andNODEBUGsupport (among other things). That removal is inline with what was discussed at the last Board meeting that prompted this PR creation. FWIW, I would continue to support and actively participate in this PR if it retains its originally intended scope. Otherwise, this PR scope has to be changed (from what was discussed at the last meeting); I do not know what the new scope of this PR is going to be, but this PR description should clarify the new scope to facilitate future re-reviews.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Alex here (obviously). Over time, we have used assert not only to check API contracts and internal invariants, but also possibly to perform user input validations. While it should be fine to not always check invariants, it would be dangerous to give up on user input validation, even if it is in rare corner cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most important problem solved by this PR is removing uncertainty for future development without paying a hefty price for that luxury. Today, in this context, we are facing this choice:
Change nothing. Continue to witness clashes among developers and among vulnerability reporters/developers on the meaning of assertions in Squid. Continue to develop on a shaky/uncertain foundation and dealing with confusing code.
Fix
NODEBUGtypos. ReducePURIFYanddefine assertcode duplication. Audit thousands of assertions and adjust a few to bring Squid code in compliance with the "assertions are optional" model.Merge the finalized version of this PR to bring Squid code in compliance with the "assertions are not optional" model.
Keeping the current status quo is clearly the worst long-term approach IMO, so I will focus on the remaining two options. Both models are reasonable. Both are used by modern projects with more development expertise. In Squid context, "assertions are not optional" model is simpler, much safer, and a lot cheaper in terms of our most precious resource (most development work has been done there already!). Thus, I think we should adopt "assertions are not optional" model and finalize/merge this PR.
P.S. I am OK with a "... but still do not put essential calls inside assertions" addendum that would eventually allow us to measure performance overhead of assertions and, if really justified, switch to the "assertions are optional" model in a distant future where associated safety loss is no longer such a significant concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am aware of multiple squid-users discussions where we have had to ask people to rebuild their Squid with assertions enabled. So there is definitely an expectation that the behaviour is supported.
You are right the macro in current Squid code having a typo. That could/should be fixed. But is separate from the need to keep supporting the
assert()suppression. There is a weak argument for keeping the typo on grounds that the people using it now expect that instead ofNDEBUG- I am not asking for that though. I am asking to retain ability to suppressassert()from some builds.The standards document says:
That forms the expectation, and defines the API symbols which we are supposed to be providing logic for.
That is a major C/C++ standard violation.
Circa Squid-3.2, Henrik and I did a full audit of squid3 codebase and removed all such
assert(...)calls. If someone has been sneaking them in again past review, those bad code changes need to be fixed immediately. C/C++ code MUST run properly when theassert(...)parameter is dropped entirely from existence by the compiler.That means no hidden side effects. Or, if some do happen, they are "harmless" things like garbage collection that could trigger at any time regardless of the
assert().FWIW, I have just finished an quick check of
git grep assertoutput. Everything still looks good to me, no sign of the "essential calls" claimed to exist.IIRC there was something else we found using
PURIFYinstead ofNDEBUG. I you want to dropPURIFYand see what breaks now, I can accept that.I still object to removing the
NODEBUG/NDEBUGsupport. Fix the typo so we don't have to argue about the naming again - but yes there are people relying on builds withoutassert()defined.There was a board meeting? I've only see invites to developer chats and core meetings. Can you point me at the minutes please.
Er, assertions have always been optional in C/C++ at the language level. AFAIK there is nothing to "switch to" - just bad coding mistakes that we eradicated over a decade ago from Squid code.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no logical connection between "somebody had disable assertions in the past (and ran into trouble)" and "we need to support disabling assertions".
As for "
PURIFYandNODEBUGbuild environment expectations", I would need to see specific squid-users discussions to confirm that they actually imply such expectations, but even if they do, it would clearly be isolated/rare incidents that should not affect the decision we are trying to make here!The typo is not separate from the "need to still honor ...
NODEBUGbuild environment expectations" claim. If we fix that typo, we will no longer those specific expectations!Needless to say, I do not think we should support such alleged use cases, even if they exist.
Yes, that is clear. IMO, that request should be rejected (for the reasons detailed earlier).
Squid
assert()macro violates that standard today. This PR essentially says that Squidassert()is not the standardassert(). That name clash is bad, but it is better than the alternative. Someday, after the backlog is dealt with, we should rename Squidassert()toxassert()or some such to remove that name clash. Today, in this PR, we are codifying the meaning of Squidassert(), not the standard one.Regardless of whether Squid bugs violate any standards, disabling Squid assertions would result in a malfunctioning Squid today. There are at least two ways to address that: Do not support disabling Squid assertions and keep fixing difficult-to-find bugs. This PR proposes the former, for several important reasons, none of which have been invalidated in your blocking review.
Both audits/checks missed at least one such bug. This should not be surprising -- it is very easy for humans to miss such bugs. As you probably know, a recent fix has added another assertion that, if disabled, resurrects a security vulnerability. There are probably more such cases, which is one of the primary reasons we should prohibit disabling Squid assertions: Disabling Squid assertions cripples Squid; the benefits of disabling assertions do not outweigh that and other associated drawbacks.
I doubt such people exist, and no concrete evidence was offered to support this "relying" claim, but my argument is much stronger than "nobody uses this feature". I argue that Squid would be much better off, on several levels, if the (currently broken) feature is removed, even if there are people that use it today. Moreover, those "people", if they do exist, will most likely not be harmed by this change!
@kinkie, this PR is unfortunately dead AFAICT -- my original arguments in its defense were not invalidated, and I doubt I can convince Amos that we are better of with always-on assertions that are, unfortunately, spelled like the optional standard ones. Sorry for the time wasted. I bet we will now have to spend more time on fixing the feature that should be removed :-(.
To me, those are Board meeting invites.
No minutes were taken -- it was an informal discussion. Please let me know if you want us to record those meetings. I recommend showing up; we often discuss important Project matters, and most of these meetings are scheduled for the time that the three of us have agreed on (and that time can be adjusted if needed).