-
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -226,9 +226,9 @@ int modify(bool enable) { | |
| printf("Couldn't create file: %s\n", path); | ||
| perror("Error"); | ||
| } else { | ||
| char str[100] = "assistive_technologies=com.sun.java.accessibility.AccessBridge\n"; | ||
| strcat_s(str, "screen_magnifier_present=true\n"); | ||
| fprintf(origFile, str); | ||
| fprintf(origFile, "%s", | ||
| "assistive_technologies=com.sun.java.accessibility.AccessBridge\n" | ||
| "screen_magnifier_present=true\n"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it is what Alexander meant. I think he meant it should look like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Damon understood me correctly. That's what I meant.
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 is in the standard, so I don't see any reason not to use it: So, in my opinion, the variable str is unnecessary here.
I suppose it should be detected during the review process for such a change. Currently, there are no format specifiers being used.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK fair enough.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can't we use 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the same comment applies here:
Thus, Similarly, it could be worth cleaning up the code to simplify the logic by not using formatted output where it's not needed. |
||
| fclose(origFile); | ||
| } | ||
| } else { | ||
|
|
@@ -314,11 +314,11 @@ void printVersion() { | |
| pVSInfo->dwProductVersionMS & 0xFFFF, | ||
| pVSInfo->dwProductVersionLS >> 16, | ||
| pVSInfo->dwProductVersionLS & 0xFFFF ); | ||
| char outputString[100]; | ||
| strcpy_s(outputString, "jabswitch "); | ||
| strcat_s(outputString, versionString); | ||
| strcat_s(outputString, "\njabswitch enables or disables the Java Access Bridge.\n"); | ||
| printf(outputString); | ||
| printf( | ||
| "jabswitch %s\n" | ||
| "jabswitch enables or disables the Java Access Bridge.\n", | ||
| versionString | ||
| ); | ||
|
Comment on lines
+317
to
+321
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
| } | ||
|
|
||
| int regEnable() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.