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

Fix snprintf always return 0 #236

Open
xchapron-ledger opened this issue Mar 27, 2023 · 0 comments
Open

Fix snprintf always return 0 #236

xchapron-ledger opened this issue Mar 27, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@xchapron-ledger
Copy link
Contributor

Initially reported here: LedgerHQ/nanos-secure-sdk#28 by @shufps

Technically man snprintf says that:

RETURN VALUE
       Upon successful return, these functions return the number of characters printed (excluding the null byte used to end output to strings).

       The functions snprintf() and vsnprintf() do not write more than size bytes (including the terminating null byte ('\0')).  If the output was truncated due to this limit, then the return value is  the
       number  of characters (excluding the terminating null byte) which would have been written to the final string if enough space had been available.  Thus, a return value of size or more means that the
       output was truncated.  (See also below under NOTES.)

       If an output error is encountered, a negative value is returned.

So always returning 0 is not a standard behavior.
However fixing this perfectly will be difficult as it would need to determine the number of char that will overrun the buffer...
I guess a first step would be to:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant