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

Add define guards to avoid multi-inclusion #17666

Closed

Conversation

liwg06
Copy link
Contributor

@liwg06 liwg06 commented Feb 8, 2022

This header files are included by multiple other headers.
It's better to add define guards to prevent multi-inclusion.

CLA: trivial

Signed-off-by: Weiguo Li liwg06@foxmail.com

Checklist
  • documentation is added or updated
  • tests are added or updated

@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Feb 8, 2022
Copy link
Contributor

@mspncp mspncp left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution @liwg06. I have one little request.

include/crypto/md32_common.h Outdated Show resolved Hide resolved
@mspncp
Copy link
Contributor

mspncp commented Feb 9, 2022

While reviewing your changes, I noticed that the path for md32_common.h is outdated in two comments:

~/src/openssl/master$ git grep -F '../md32_common'

crypto/sha/sha1dgst.c:/* The implementation is in ../md32_common.h */
crypto/sha/sha512.c: *   implementations, ../md32_common.h;

It should be crypto/md32_common.h instead of ../md32_common.h. Would you mind correcting them (in a separate commit) while you are at it?

@mspncp mspncp added the cla: trivial One of the commits is marked as 'CLA: trivial' label Feb 9, 2022
@mspncp
Copy link
Contributor

mspncp commented Feb 9, 2022

For the record: I agree that this is a trivial change.

@mspncp mspncp added the branch: master Merge to master branch label Feb 9, 2022
@liwg06 liwg06 force-pushed the define-guard-avoid-multi-inclusion branch from b0f6117 to 7601e57 Compare February 9, 2022 07:52
@liwg06
Copy link
Contributor Author

liwg06 commented Feb 9, 2022

Current commit is updated by your advice. @mspncp
With pleasure, fix outdated comments at another commit #17670

Copy link
Contributor

@mspncp mspncp left a comment

Choose a reason for hiding this comment

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

LGTM

@mspncp mspncp added the approval: review pending This pull request needs review by a committer label Feb 9, 2022
@t8m
Copy link
Member

t8m commented Feb 9, 2022

I am not sure this would be acceptable with CLA: trivial. Could you please consider signing the CLA?

@t8m t8m added the hold: cla required The contributor needs to submit a license agreement label Feb 9, 2022
#ifndef OSSL_CRYPTO_MD32_COMMON_H
# define OSSL_CRYPTO_MD32_COMMON_H
# pragma once

#include <openssl/crypto.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Style NIT: we indent preprocessor directives, so all preprocessor lines inside the new #ifndef should gain a space.

Copy link
Contributor

@mspncp mspncp Feb 9, 2022

Choose a reason for hiding this comment

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

That's true in principle, but there are other locations where include guards were added afterwards and not the entire indentation of the preprocessor directives was adjusted. (I checked the fact, because I had the same idea.) That's why I didn't want to bother the submitter by requesting it.

Copy link
Contributor

Choose a reason for hiding this comment

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

But sure, if @liwg06 would volunteer to fix it, that would be great!

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 clone the repo again to dismiss the intermediate results of local compilation, then search the current practice for define guard:
grep -rn ./openssl/ --include=*.h -e "#ifndef.*_H$" -A 1|grep "# define "|wc -l
271
grep -rn ./openssl/ --include=*.h -e "#ifndef.*_H$" -A 1|grep "#define "|wc -l
8
It shows that (may be not accurate) 271 define guards are followed by "# define xxx", and 8 by "#define xxx", so this patch consistent with the majority.

I'm not sure whether I got what you talk about. @paulidale @mspncp
Is it change pattern A to pattern B?
patern A:

#ifndef OSSL_XXX_H
# define OSSL_XXX_H
# pragma once

patern B:

#ifndef OSSL_XXX_H
#define OSSL_XXX_H
#pragma once 

If so, I'll update the commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is pattern A.

More precisely: we indent conditional blocks like C-blocks, using spaces between # and the directive. Since you added an extra #ifndef ... #endif block, all enclosed preprocessor directives would need an extra space of indentation:

#ifndef OSSL_XXX_H
# if FOO
#  if BAR 
#   define FOOBAR
#  endif
# endif
#endif

Copy link
Contributor

@mspncp mspncp Feb 9, 2022

Choose a reason for hiding this comment

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

But as you already noticed, there are places in our source code where the indentation is not as it should be.

Copy link
Member

Choose a reason for hiding this comment

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

@liwg06 What we are asking for is to indent the preprocessor directives further in the source code if you are adding another #ifndef around it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.
I use the script to indent the line begien with "#" in target files at first, and then add the define guard.

for filename in $(ls \
 include/crypto/md32_common.h \
 include/internal/der.h \
 include/internal/tsan_assist.h \
 providers/implementations/include/prov/ciphercommon.h \
 providers/implementations/include/prov/ciphercommon_aead.h \
 providers/implementations/include/prov/ciphercommon_ccm.h \
 providers/implementations/include/prov/ciphercommon_gcm.h ) ; \
do cat $filename | sed 's/^#/# /' > $filename.new.h ; mv $filename.new.h $filename ; done

The commit is updated, I will check the CI result later.

@liwg06 liwg06 force-pushed the define-guard-avoid-multi-inclusion branch from 7601e57 to ceb5c22 Compare February 9, 2022 18:34
@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label Feb 9, 2022
@liwg06 liwg06 force-pushed the define-guard-avoid-multi-inclusion branch from ceb5c22 to e850c9a Compare February 9, 2022 18:50
@t8m t8m added the triaged: feature The issue/pr requests/adds a feature label Feb 10, 2022
@t8m
Copy link
Member

t8m commented Feb 10, 2022

Although the change is probably not really copyrightable, could you please sign the CLA and drop the CLA: trivial? https://www.openssl.org/policies/cla.html

@t8m t8m added the hold: cla required The contributor needs to submit a license agreement label Feb 10, 2022
@liwg06
Copy link
Contributor Author

liwg06 commented Feb 10, 2022

It may not really need to sign the CLA, since the fix is really trivial. Thanks for your remind again. @t8m

@t8m
Copy link
Member

t8m commented Feb 10, 2022

It does not matter whether the fix is trivial or not. We require a regular CLA for commits that are beyond simple typo fixes and other trivial one to two line changes.

@mspncp
Copy link
Contributor

mspncp commented Feb 10, 2022

I sent a slight disagreement whether this kind of change can be considered trivial (in the legal sense). After ignoring whitespace differences all that remains is the addition of include guards. IMHO this is a trivial change.

I suggest that the OTC discuss this next tuesday.

@liwg06 please be so kind and be a little patient with us :-)

@mspncp mspncp added the hold: need otc decision The OTC needs to make a decision label Feb 10, 2022
@mspncp
Copy link
Contributor

mspncp commented Feb 10, 2022

After ignoring whitespace differences ...

Note: all these whitespace diffs were caused by @paulidale's and my request to reindent the preprocessor directives. The original pull request was as simple as b0f6117787cd61425987cbda55c294fd06de492e.

@t8m
Copy link
Member

t8m commented Feb 10, 2022

I sent a slight disagreement whether this kind of change can be considered trivial (in the legal sense).

I am not really disputing the fact, that this kind of change is trivial (i.e., uncopyrightable in the legal sense). I am saying that we do not accept such large changes (even if the whitespace changes were not there) with CLA: trivial.

@mspncp
Copy link
Contributor

mspncp commented Feb 10, 2022

I agree that this is the current practice, but it is not an immutable rule. IMHO it could (and should) be governed by an explicit OTC policy.

@mspncp
Copy link
Contributor

mspncp commented Feb 10, 2022

I sent a slight disagreement...

Ups, of course I meant to write scent, not sent 😊

@t8m
Copy link
Member

t8m commented Feb 10, 2022

IMO what is acceptable with CLA: trivial and what not is rather an OMC topic.

This header files are included by multiple other headers.
It's better to add define guards to prevent multi-inclusion.
Adhere to the coding style, all preprocessor directives inside
the guards gain a space.

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
@liwg06 liwg06 force-pushed the define-guard-avoid-multi-inclusion branch from e850c9a to 76d0357 Compare February 10, 2022 16:40
@liwg06
Copy link
Contributor Author

liwg06 commented Feb 10, 2022

I have singed the CLA and updated the commit log.
Sorry to cause a controversy... @t8m @mspncp

@liwg06
Copy link
Contributor Author

liwg06 commented Feb 10, 2022

Since I removed the "CLA: trivial" in commit log, CI test failed at cla-check case.

@mspncp
Copy link
Contributor

mspncp commented Feb 10, 2022

Don't worry about it, just wait till the CLA is registered. Then the ticket will be closed and reopenend and the CLA bot will be content.

@mspncp
Copy link
Contributor

mspncp commented Feb 10, 2022

Sorry to cause a controversy... @t8m @mspncp

No need to worry. With disagreement I just meant that we are having different opinions, not that we are having a quarrel. :-)

@mspncp
Copy link
Contributor

mspncp commented Feb 10, 2022

Don't worry about it, just wait till the CLA is registered. Then the ticket will be closed and reopenend and the CLA bot will be content.

In fact, you fulfilled all your requirements. All you need to do now is sit back and relax until your pull request gets merged.

@mspncp mspncp removed the hold: need otc decision The OTC needs to make a decision label Feb 10, 2022
@mspncp
Copy link
Contributor

mspncp commented Feb 10, 2022

I removed the OTC hold since you sent a CLA. Even if we discuss it next week, it won't affect your pull request anymore.

@mspncp mspncp removed the cla: trivial One of the commits is marked as 'CLA: trivial' label Feb 10, 2022
@liwg06
Copy link
Contributor Author

liwg06 commented Feb 10, 2022

'◡'

@liwg06 liwg06 closed this Feb 15, 2022
@liwg06 liwg06 reopened this Feb 15, 2022
@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label Feb 15, 2022
@mspncp
Copy link
Contributor

mspncp commented Feb 15, 2022

Ping @openssl/committers for second review. (You might also want to review with whitespace-diffs hidden. A large part of the diffs is caused by reindentation of the preprocessor directives.)

@t8m t8m added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Feb 15, 2022
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Feb 16, 2022
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

openssl-machine pushed a commit that referenced this pull request Feb 16, 2022
This header files are included by multiple other headers.
It's better to add define guards to prevent multi-inclusion.
Adhere to the coding style, all preprocessor directives inside
the guards gain a space.

Signed-off-by: Weiguo Li <liwg06@foxmail.com>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from #17666)
@mspncp
Copy link
Contributor

mspncp commented Feb 16, 2022

Merged to master in 3d27ac8. Thank you!

@mspncp mspncp closed this Feb 16, 2022
dongbeiouba added a commit to dongbeiouba/Tongsuo that referenced this pull request Mar 7, 2024
This header files are included by multiple other headers.
It's better to add define guards to prevent multi-inclusion.
Adhere to the coding style, all preprocessor directives inside
the guards gain a space.

Signed-off-by: Weiguo Li <liwg06@foxmail.com>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from openssl/openssl#17666)
dongbeiouba added a commit to dongbeiouba/Tongsuo that referenced this pull request Mar 25, 2024
This header files are included by multiple other headers.
It's better to add define guards to prevent multi-inclusion.
Adhere to the coding style, all preprocessor directives inside
the guards gain a space.

Signed-off-by: Weiguo Li <liwg06@foxmail.com>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from openssl/openssl#17666)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Merge to master branch severity: fips change The pull request changes FIPS provider sources triaged: feature The issue/pr requests/adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants