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

critical: string formatting bug leading to invalid ulog files #12485

Closed
bkueng opened this issue Jul 15, 2019 · 3 comments
Closed

critical: string formatting bug leading to invalid ulog files #12485

bkueng opened this issue Jul 15, 2019 · 3 comments

Comments

@bkueng
Copy link
Member

bkueng commented Jul 15, 2019

On master the following code:

        char b[50];
        size_t s = 5;
        snprintf(b, sizeof(b), "char[%zu] %s", s, "test");
        printf("b=%s\n", b);
        printf("char[%zu] %s\n", s, "test");
        snprintf(b, sizeof(b), "%zu", s);
        printf("b=%s\n", b);
        printf("%zu\n", s);

produces:

b=char[%zu] test
char[%zu] test
b=%zu
%zu

on NuttX. The expected output is:

b=char[5] test
char[5] test
b=5
5

As a result all (!) log files are invalid. The reason why it still works is that pyulog does not look at that field for string lengths, but FlightPlot for instance won't open the log.

%zu is both a valid C99 and C11 format specifier. It is used in the logger and at a few other places.

The commit that breaks it is the NuttX upgrade (dc10a68).

@davids5 can you have a look?

bkueng added a commit that referenced this issue Jul 16, 2019
Work-around for #12485.

This can be reverted after the root-cause is fixed.
bkueng added a commit that referenced this issue Jul 16, 2019
Work-around for #12485.

This can be reverted after the root-cause is fixed.
@davids5
Copy link
Member

davids5 commented Jul 22, 2019

@bkueng - The change was introduced in the new stdio/lib_libvsprintf.c. The legacy_libvsprintf is still available but uses more space. Let me see if I can upstream a fix and backport it.

@davids5
Copy link
Member

davids5 commented Jul 22, 2019

@bkueng - PR submitted upstream - I will back port if it goes in or added at as a reject if not.

@stale stale bot added the stale label Oct 20, 2019
@PX4 PX4 deleted a comment from stale bot Oct 21, 2019
@stale stale bot removed the stale label Oct 21, 2019
@davids5
Copy link
Member

davids5 commented Oct 21, 2019

Fixed in PX4/NuttX#56

@davids5 davids5 closed this as completed Oct 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants