ARMmbed / mbed-os

Arm Mbed OS is a platform operating system designed for the internet of things
https://mbed.com
Other
4.67k stars 2.98k forks source link

mkdir() and stat() do not set errno on all error cases #5362

Closed TeroJaasko closed 6 years ago

TeroJaasko commented 6 years ago

Note: This is just a template, so feel free to use/remove the unnecessary things

Description


Bug

Target K64F

Toolchain: GCC_ARM

Toolchain version:

mbed-cli version: 1.2.0

mbed-os sha: 6e0d01c (HEAD, tag: mbed_lib_rev153, tag: mbed-os-5.6.2, origin/mbed-os-5.6) Merge pull request #5268 from ARMmbed/release-candidate

Expected behavior When mkdir() or stat() fail for any reason, on POSIX they are document to return "-1" and errno is set appropriately.

Actual behavior If a invalid filename is given, the errno is not set, but a -1 is returned. This will make the client code behave badly as it tries to determine error reason from errno.

Steps to reproduce On Mbed OS 5.6.2 following code will print "mkdir err: -1, errno: 1234"

void do_error()
{
    errno = 1234; // set garbage to errno, should be set to proper error code by mkdir()
    int ret = mkdir("foo", 0777);
    if (ret < 0) {
        printf("mkdir ret: %d, errno: %d\r\n", ret, errno);
    } else {
        printf("mkdir ret: %d - OK\r\n", ret);
    }
}

Enhancement

Reason to enhance or problem with existing solution

Suggested enhancement Set errno also in these conditions which return -1: https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed_retarget.cpp#L682 https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed_retarget.cpp#L696

Pros

Cons


Question

How to?

geky commented 6 years ago

Easy fix, thanks for reporting: https://github.com/ARMmbed/mbed-os/pull/5373