CMFSUPPORT-3863. COVERITY TEST. DO NOT MERGE#58
CMFSUPPORT-3863. COVERITY TEST. DO NOT MERGE#58scthunderbolt wants to merge 1 commit intodevelopfrom
Conversation
| if ((file = fopen(fpath, "w"))) | ||
| { | ||
| fprintf(file,"%s",str); | ||
| fprintf(file,"%s%s",str); |
Check warning
Code scanning / CodeQL
Too few arguments to formatting function Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
In general, to fix “too few arguments to formatting function” issues, you must ensure that the number and types of arguments after the format string match the format specifiers inside it. Either remove unused format specifiers or add the missing arguments.
For this specific case in source/AdvSecurityDml/cosa_adv_security_internal.c, in advsec_write_to_file, the code is:
if ((file = fopen(fpath, "w")))
{
fprintf(file,"%s%s",str);
fclose(file);
return 1;
}The function takes a single string str to be written to the file, and there is no second string available or needed. The extra %s in the format string is therefore erroneous. To fix this without changing existing functionality, change the fprintf format string from "%s%s" to "%s", which correctly matches the single str argument and preserves the intended behavior of writing exactly str to the file.
No new methods, imports, or definitions are needed; only this one-line format string change is required.
| @@ -294,7 +294,7 @@ | ||
|
|
||
| if ((file = fopen(fpath, "w"))) | ||
| { | ||
| fprintf(file,"%s%s",str); | ||
| fprintf(file, "%s", str); | ||
| fclose(file); | ||
| return 1; | ||
| } |
There was a problem hiding this comment.
Pull request overview
This PR modifies the internal helper used to write strings to a file in the Advanced Security DML component.
Changes:
- Updates the
fprintfformat string used byadvsec_write_to_file().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fprintf(file,"%s%s",str); | ||
| fclose(file); | ||
| return 1; |
There was a problem hiding this comment.
fprintf(file, "%s%s", str); is undefined behavior because the format string expects two %s arguments but only one is provided. This can crash or leak stack data. Use a single %s (or add the intended second string argument, e.g., a newline/terminator) and consider checking fprintf’s return value if write failures matter here.
| fprintf(file,"%s%s",str); | |
| fclose(file); | |
| return 1; | |
| int written = fprintf(file, "%s", str); | |
| fclose(file); | |
| return (written >= 0) ? 1 : 0; |
| if ((file = fopen(fpath, "w"))) | ||
| { | ||
| fprintf(file,"%s",str); | ||
| fprintf(file,"%s%s",str); |
Check failure
Code scanning / Coverity
Missing argument to printf format specifier High
| if ((file = fopen(fpath, "w"))) | ||
| { | ||
| fprintf(file,"%s",str); | ||
| fprintf(file,"%s%s",str); |
Check notice
Code scanning / Coverity
Printf arg count mismatch Low
No description provided.