Conversation
…heck for a 'scanf'-like function Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a code scanning security alert by fixing an incorrect return-value check for a fscanf function call. The change ensures that the return value is explicitly compared to the expected number of items (1) rather than just testing for nonzero, which could incorrectly treat EOF or partial reads as success.
Changes:
- Updated the
fscanfreturn value check on line 2134 from an implicit nonzero test to an explicit== 1comparison - Added proper code formatting with consistent spacing
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
zhblue
added a commit
that referenced
this pull request
Jan 21, 2026
* Refactor contest ranking logic in contestrank.xls.php * Sanitize nicknames with additional prefix check * Remove '../' from file names in problem import Sanitize file names by removing '../' to prevent directory traversal vulnerabilities. * Add exit to restrict access to proxy.php Added exit statement to prevent unauthorized access. * Update problem_import_hoj.php * Update problem_import_hydro.php * Update problem_import_md.php * Update problem_import_qduoj.php * Update problem_import_syzoj.php * Update problem_import_tyvj.php * Update problem_import_unkownoj.php * Update problem_import_hoj.php * Update my_func.inc.php * Update problem_import.php * Update problem_import_qduoj.php * Update problem_import_hoj.php * Update problem_import_qduoj.php * Update difficulty control standards in common.php * Update mail.php * Fix HTML form attributes in mail.php * Update mail.php * Potential fix for code scanning alert no. 4: Time-of-check time-of-use filesystem race condition (#1118) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for code scanning alert no. 6: Incorrect return-value check for a 'scanf'-like function (#1120) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
zhblue
added a commit
that referenced
this pull request
Jan 21, 2026
* Refactor contest ranking logic in contestrank.xls.php * Sanitize nicknames with additional prefix check * Remove '../' from file names in problem import Sanitize file names by removing '../' to prevent directory traversal vulnerabilities. * Add exit to restrict access to proxy.php Added exit statement to prevent unauthorized access. * Update problem_import_hoj.php * Update problem_import_hydro.php * Update problem_import_md.php * Update problem_import_qduoj.php * Update problem_import_syzoj.php * Update problem_import_tyvj.php * Update problem_import_unkownoj.php * Update problem_import_hoj.php * Update my_func.inc.php * Update problem_import.php * Update problem_import_qduoj.php * Update problem_import_hoj.php * Update problem_import_qduoj.php * Update difficulty control standards in common.php * Update mail.php * Fix HTML form attributes in mail.php * Update mail.php * Potential fix for code scanning alert no. 4: Time-of-check time-of-use filesystem race condition (#1118) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for code scanning alert no. 6: Incorrect return-value check for a 'scanf'-like function (#1120) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for code scanning alert no. 5: Incorrect return-value check for a 'scanf'-like function (#1119) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Update date formatting in submit.php Replaced strftime with date for better date formatting. * Update submit.php --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/zhblue/hustoj/security/code-scanning/6
In general, calls to
scanf-like functions should compare their return value to the exact number of expected input items, not just test for nonzero. Here,fscanf(fpname,"%s",noip_file_name)is expected to read exactly one string, so the correct condition isif (fscanf(...) == 1)(or equivalently, store the result in a variable and checkr == 1orr < 1). This ensures that neither partial reads norEOFare treated as success.To fix the specific problem without changing functionality, update the
ifcondition on line 2134 to explicitly compare the return value offscanfagainst1. The surrounding logic (debug prints,basenameusage,execute_cmd, andfclose) should remain unchanged. No new methods, imports, or definitions are required, since we are only tightening the return-value check semantics on an existing standard-library call.Concretely, in
trunk/core/judge_client/judge_client.cc, locate the block around the second use offpname(the one foroutput.name) and change:to:
leaving indentation and the rest of the function intact.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.