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

Handle negative values passed to close() #15431

Merged
merged 2 commits into from
Jul 3, 2023
Merged

Conversation

alrvid
Copy link
Contributor

@alrvid alrvid commented Jun 14, 2023

Summary of changes

Calling close() with negative numbers causes out-of-bounds indexing of the filehandles array. For example, this can happen if open() returns an error and the value is later passed to close(). The fix simply returns the correct error code for an invalid file descriptor.

Impact of changes

Migration actions required

Documentation

None


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


Calling close() with negative numbers causes out-of-bounds indexing of the filehandles array. For example, this can happen if open() returns an error and the value is later passed to close().
Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

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

Otherwise looks good

@@ -656,6 +656,11 @@ extern "C" int PREFIX(_close)(FILEHANDLE fh)
#if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
extern "C" int close(int fildes)
{
if (fildes < 0)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be aligned to if statement (line 659 please)

@0xc0170 0xc0170 added needs: work release-type: patch Indentifies a PR as containing just a patch labels Jun 15, 2023
Moved a { to the same line as if
@mergify mergify bot dismissed 0xc0170’s stale review June 15, 2023 13:39

Pull request has been modified.

@alrvid alrvid requested a review from 0xc0170 June 15, 2023 13:46
@0xc0170
Copy link
Contributor

0xc0170 commented Jun 26, 2023

CI started

@mbed-ci
Copy link

mbed-ci commented Jun 26, 2023

Jenkins CI Test : ❌ FAILED

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test

@mergify mergify bot added needs: work and removed needs: CI labels Jun 26, 2023
@0xc0170
Copy link
Contributor

0xc0170 commented Jun 28, 2023

CI restarted

@mbed-ci
Copy link

mbed-ci commented Jun 28, 2023

Jenkins CI Test : ✔️ SUCCESS

Build Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️

@alrvid alrvid requested a review from 0xc0170 June 30, 2023 15:46
@0xc0170 0xc0170 merged commit f9c0cd2 into ARMmbed:master Jul 3, 2023
10 checks passed
@mergify mergify bot removed the ready for merge label Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-type: patch Indentifies a PR as containing just a patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants