-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8373474: 2 Unintentional format string defect groups in jabswitch.cpp #28949
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
Conversation
|
👋 Welcome back dnguyen! A progress list of the required criteria for merging this PR into |
|
@DamonGuy This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 132 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
| fprintf(origFile, str); | ||
| fprintf(origFile, | ||
| "assistive_technologies=com.sun.java.accessibility.AccessBridge\n" | ||
| "screen_magnifier_present=true\n"); |
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 don't think it is what Alexander meant.
I am not sure doing the above would even resolve the complaint because there's still no format string.
I think he meant it should look like
fprintf(origfile, "%s",
"assistive_technologies=com.sun.java.accessibility.AccessBridge\n"screen_magnifier_present=true\n");
or
fprintf(origfile, "%s",
"assistive_technologies=com.sun.java.accessibility.AccessBridge\n" "screen_magnifier_present=true\n");
if you really want to use the automatic concatenation, but I had to check to be sure it would work so ..
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 your point. I'll leave it as separated again just in case the string literal is updated with anything that can be misinterpreted as a specifier.
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 don't think it is what Alexander meant.
Damon understood me correctly. That's what I meant.
#28949 (comment)
I am not sure doing the above would even resolve the complaint because there's still no format string.
It should.
before:
fprintf(origFile, str); // using `str` variable as format string > parfait complainsafter:
fprintf(origFile,
"assistive_technologies=com.sun.java.accessibility.AccessBridge\n"
"screen_magnifier_present=true\n"); Here, we provide a format string(without the format specifiers), not the variable.
It's essentially identical to the code on line 301, printf("Unable to get version info.\n");, parfait didn't complain about that line.
if you really want to use the automatic concatenation, but I had to check to be sure it would work so ..
It is in the standard, so I don't see any reason not to use it:
https://en.cppreference.com/w/cpp/language/string_literal.html#Concatenation
So, in my opinion, the variable str is unnecessary here.
just in case the string literal is updated with anything that can be misinterpreted as a specifier.
I suppose it should be detected during the review process for such a change. Currently, there are no format specifiers being used.
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.
OK fair enough.
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.
Why can't we use fputs?
fputs("assistive_technologies=com.sun.java.accessibility.AccessBridge\n"
"screen_magnifier_present=true\n",
origFile);No format strings avoid any possible ambiguity and it's much faster as the string is output verbatim without any additional logic to parse a format string and to process the arguments.
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 guess the same comment applies here:
A similar pattern is used elsewhere in this file. And I don't want this fix to become a reworking of this code, because that isn't a goal here.
Thus, fprintf is fine.
Similarly, it could be worth cleaning up the code to simplify the logic by not using formatted output where it's not needed.
| fprintf(origFile, str); | ||
| fprintf(origFile, | ||
| "assistive_technologies=com.sun.java.accessibility.AccessBridge\n" | ||
| "screen_magnifier_present=true\n"); |
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.
Why can't we use fputs?
fputs("assistive_technologies=com.sun.java.accessibility.AccessBridge\n"
"screen_magnifier_present=true\n",
origFile);No format strings avoid any possible ambiguity and it's much faster as the string is output verbatim without any additional logic to parse a format string and to process the arguments.
| printf( | ||
| "jabswitch %s\n" | ||
| "jabswitch enables or disables the Java Access Bridge.\n", | ||
| versionString | ||
| ); |
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.
If versionString isn't used for anything else, we can remove the versionString variable and the call to sprintf_s and put the arguments to print the version directly into the printf call.
| fprintf(origFile, str); | ||
| fprintf(origFile, | ||
| "assistive_technologies=com.sun.java.accessibility.AccessBridge\n" | ||
| "screen_magnifier_present=true\n"); |
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 guess the same comment applies here:
A similar pattern is used elsewhere in this file. And I don't want this fix to become a reworking of this code, because that isn't a goal here.
Thus, fprintf is fine.
Similarly, it could be worth cleaning up the code to simplify the logic by not using formatted output where it's not needed.
|
/integrate |
|
Going to push as commit 72e1e15.
Your commit was automatically rebased without conflicts. |
This issue is not currently causing any problems, but I am adding specifiers to explicitly print these strings. This is to avoid any issues down the line where changes to the lines building the string can cause any accidental formatting. Overall, this should be a harmless update and improves the stability and reliability of printing these strings.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28949/head:pull/28949$ git checkout pull/28949Update a local copy of the PR:
$ git checkout pull/28949$ git pull https://git.openjdk.org/jdk.git pull/28949/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28949View PR using the GUI difftool:
$ git pr show -t 28949Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28949.diff
Using Webrev
Link to Webrev Comment