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

Consistent returns from ssnprintf/__ssnprintf wrappers, add ssnprintf2 for optional error handling. #3283

Merged
merged 5 commits into from
Nov 2, 2019

Conversation

zebity
Copy link
Contributor

@zebity zebity commented Sep 18, 2019

ChangeLog: collectd: Consistent ssnprintf/__ssnprintf returns, new ssnprintf2 for error handling.

@mrunge cherry picked fix for ssnprintf wrapper #3237 (mea culpa) back into master, thank you @faxm0dem . Applied same update to __ssnprintf wrapper in src/collectdctl.c for return result consistency and ensured opening comments consistent with code.

As per original suggestion from @octo (#2895) I have also added second wrapper ssnprintf2 into src/utils/common/common.c . This has the same return behaviour of original suggestion (which resulted in problem), so that in future if we want to add error handling for truncation (rather than ignore it) then this can be done on case by case basis.

The degree of impact of adding truncation error handling is to large to do in single hit, as I don't want to risk breaking code base a second time.

Thanks to all for continued updates into collectd.

Fᴀʙɪᴇɴ Wᴇʀɴʟɪ and others added 3 commits September 18, 2019 21:10
@zebity zebity changed the title Provide consistent ssnprintf/__ssnprintf returns and add ssnprintf2 for optional error handling Ensure consistent ssnprintf/__ssnprintf wrapper returns. Add ssnprintf2 for optional error handling. Sep 18, 2019
@zebity zebity changed the title Ensure consistent ssnprintf/__ssnprintf wrapper returns. Add ssnprintf2 for optional error handling. ChangeLog: ssnprintf wrappers: Ensure consistent returns, add ssnprintf2 for optional error handling. Sep 18, 2019
@zebity zebity changed the title ChangeLog: ssnprintf wrappers: Ensure consistent returns, add ssnprintf2 for optional error handling. Ensure consistent ssnprintf/__ssnprintf wrappers returns, add ssnprintf2 for optional error handling. Sep 18, 2019
@zebity zebity changed the title Ensure consistent ssnprintf/__ssnprintf wrappers returns, add ssnprintf2 for optional error handling. Consistent returns from ssnprintf/__ssnprintf wrappers, add ssnprintf2 for optional error handling. Sep 18, 2019
@mrunge
Copy link
Member

mrunge commented Sep 19, 2019

Thank you, I'll try to get back to this asap.

@mrunge mrunge added this to the 5.10.0 milestone Oct 11, 2019
@@ -89,8 +89,7 @@ char *sstrncpy(char *dest, const char *src, size_t n) {
return dest;
} /* char *sstrncpy */

/* ssnprintf returns zero on success, one if truncation occurred
and a negative integer onerror. */
/* ssnprintf returns result from vsnprintf conistent with snprintf */
Copy link
Contributor

Choose a reason for hiding this comment

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

so how is this function different then from snprintf?

Copy link
Contributor Author

@zebity zebity Oct 21, 2019

Choose a reason for hiding this comment

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

Hi @rubenk the ssnprintf wrapper was introduced to get around GCC 8.2/.3 warning, only, there is no functional difference.
The original suggested fix included changing return to allow handling of truncation, however as this broke stuff.
So I to allow for future handling of truncation, case I added ssnprintf2 case.
Also to ensure that the other case that had the alternated return case (in collectdctl.c), I updated this to be consistent with snprintf.
As per discussion below, this was all driven by compiler behaviour rather than feature/fix need and yes the amount of code touched was greater than desired.
Cheers.


/* ssnprintf2 returns zero on success, one if truncation occurred
and a negative integer on error. */
int ssnprintf2(char *str, size_t sz, const char *format, ...) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that this does exactly the same as snprintf and ssnprintf, or am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

The return value is different, and I assume the idea is to provide both.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can detect truncation with snprintf just fine, so I don't see how this helps.

@rubenk
Copy link
Contributor

rubenk commented Oct 14, 2019

I'm sorry for perhaps sounding so negative, but this has all turned into a bit of a mess.
The original issue as I see it is two-fold:

  • gcc started warning for potential truncation.
  • we turn all warnings into errors, which breaks peoples builds.

Some of those truncation issues are real and we should fix them, some of them are not. Adding wrappers around them will never get them fixed. Admittingly checking every call site is a lot of work.

What I'd rather see is that we stop building with -Werror by default (most distros already turn that of). We could then turn -Werror on in CI, but turn the truncation errors into warnings (-Wno-error=stringop-truncation or something like that). We'll still see the warnings and can fix them in due time.

How does that sound?

@mrunge
Copy link
Member

mrunge commented Oct 14, 2019

I agree, this sounds like a good plan to go forward.

So the next step(s) would be to revert the ssnprintf changes and to fix potential truncation.

Ideally, we'd remove ssnprintf and at the same time, fixing truncation warnings. I'd prefer to keep warnings as errors.

@zebity
Copy link
Contributor Author

zebity commented Oct 21, 2019

@rubenk & @mrunge,

sounds like a plan.

Wrapper was put in place due to number of places that -Werror broke build.

Remember that if you keep -Werror on in CI then all the builds will fail :-(

The amount of work required to get rid of warnings (assuming change the compile flags) is around approximately 67 files that where updated originally. It was the large number of files being changed that blocked getting this done.

I suspect that most of these files are dormant in terms of change so getting them fixed on an "as needs" basis will be slow process.

BTW, if we do turn off of -Werror with -W-Wno-error=stringop-truncation then its pretty easy to wind out all the auto-edits back to where they were, as I have record of all the original changs.

Cheers,

zebity

@zebity
Copy link
Contributor Author

zebity commented Oct 22, 2019

@mrunge @rubenk @rpv-tomsk

a quick find / grep indicates that there are 67 files with ssnprintf wrapper and 19 of these actually appear to use the return value.

So if any rework is going to be done then it would make sense to start with ones that use the return value, as these are potentially sensitive to truncation.

On different note, the number of plugins (there are around 60 libraries required to build for Debian package) and potential rate of change across these means that the release rate will have turn up substantially to allow collectd to keep up with changes forced to keep plugins current.

I think this is reflected by the very number of forked repositories.

Cheers,

Zebity.

@mrunge
Copy link
Member

mrunge commented Oct 22, 2019

Thank you @zebity . What do you mean by "release rate"? Release rates for collectd? You may have seen #3318 ?

@zebity
Copy link
Contributor Author

zebity commented Oct 23, 2019

@mrunge yes to #3318 and I commend and thank you for your hard graft in keeping the wheels turning.

I was just doing some "out loud thinking...". I have been looking at the GitHub statistics and it would be really helpful to have some sense of rate of change across the entire code base (ie change with core vs change within pluggins and bug fix / currency driven change vs feature change.
I dwell on this due to my dear old debian packaging still languishing at 8.x ... :-(

Also I am a bit stunned by the 1000 or so forks... are these all mostly dormant or is there a whole lot of work happening outside of main branch ?

As I said I so just "thinking out loud" and will see if I can pull together some sort of statistical view.

EDIT: Also so I have reviewed the 5.10 open list and see this merge is one of items. My proposal at this point is remove the wrapper from the 19 functions that use the return (or least try to.., with appropriate caution and testing) and to leave the others us is (otherwise we will never get 5.10 out the door). Let me know your thoughts and I will do my bit of the work.

@zebity
Copy link
Contributor Author

zebity commented Nov 2, 2019

@rjablonx @mrunge I ask if you could please review and merge this request.

I have now wound out anything that is pre-emptive of immediate need (ie ssnprintf2 proposal), so change now just ensures that collectdctl.c is aligned with @faxm0dem fix (#3237).

I will not do any further changes related to the ssnprintf wrappers via this request.
This is In line with need to keep regular cadence as per discussion thread #3223
I believe that any further work on add/remove/tweeking build flags should be tackled and managed as individual merge requests and not a bulk change.

I think that is is consistent with approach of letting primary owner / maintainers of the various 67 files updated to be able to be involved in any further remediation.

For the initial identified set of 29, I believe the best approach would be equivalent 29 individual pull requests, which can run then there own course and with their own priority.
While this might seen onerous in terms of impact to release process, if we get greater level of automation going then it should allow ongoing smoother regular patch level releases, starting from new 5.10.0 release.

I will be good to get this initial bulk change (and associated formatting clean up) done and dusted.

Cheers,

Zebity

Copy link
Member

@mrunge mrunge 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 work on this!

@mrunge mrunge merged commit 5c35a31 into collectd:master Nov 2, 2019
@zebity
Copy link
Contributor Author

zebity commented Nov 5, 2019

@mrunge many thanks.

FYI, I have updated test server to Ubuntu 19.10 so next step will be to test current 5.9.2/5.10.0 build against that and ensure all is ok on this update.

Cheers,

Zebity

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

4 participants