Could sprintf be replaced with snprintf?
I am using some Boost libraries in a code base that does not want any use of sprintf. An automatic test flags any calls to it or vsprintf. Is it possible to replace all uses of sprintf with snprintf? I really doubt there are actually any security issues here, but I'm hoping this wouldn't be too difficult or cause any problems other than the effort to do it. Cheers, Justin
On Wed, Nov 15, 2023 at 17:56, McGrath, Justin M via Boost-users <[boost-users@lists.boost.org](mailto:On Wed, Nov 15, 2023 at 17:56, McGrath, Justin M via Boost-users <<a href=)> wrote:
I am using some Boost libraries in a code base that does not want any use of sprintf. An automatic test flags any calls to it or vsprintf.
Is it possible to replace all uses of sprintf with snprintf? I really doubt there are actually any security issues here, but I'm hoping this wouldn't be too difficult or cause any problems other than the effort to do it.
Cheers, Justin _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
Justin, Which libraries are you using that have that issue? Matt
Hi Matt,
In ODEINT it's called in max_step_checker.hpp.
```
const int m_max_steps;
...
char error_msg[200];
std::sprintf(error_msg, "Max number of iterations exceeded (%d).", m_max_steps);
...
char error_msg[200];
std::sprintf(error_msg, "Max number of iterations exceeded (%d).", m_max_steps);
```
It looks to me that neither of these uses could possibly overflow, but for whatever reason people have latched onto the idea that sprintf should never be used.
Cheers,
Justin
________________________________________
From: Matt Borland
On Nov 16, 2023, at 4:22 PM, McGrath, Justin M
wrote: Hi Matt, In ODEINT it's called in max_step_checker.hpp.
``` const int m_max_steps; ... char error_msg[200]; std::sprintf(error_msg, "Max number of iterations exceeded (%d).", m_max_steps); ... char error_msg[200]; std::sprintf(error_msg, "Max number of iterations exceeded (%d).", m_max_steps);
```
It looks to me that neither of these uses could possibly overflow, but for whatever reason people have latched onto the idea that sprintf should never be used.
Cheers, Justin
Justin, It looks like someone filed a PR about a year ago to fix that: https://github.com/boostorg/odeint/pull/58 , but the last commit to ODEINT is spring of 2019. I cc’ed the maintainer so hopefully he sees this. Matt
Thanks Matt.
________________________________________
From: Matt Borland
Hi Matt,
It's been a while and I haven't heard from Mario. I tried a different email address I found on this CV, but didn't get a reply, and I can't find any contact information for Karsten Ahnert. Do you have other ideas about how to contact them, or could someone else step in as a maintainer?
Best wishes,
Justin
________________________________________
From: McGrath, Justin M
On Nov 29, 2023, at 9:39 PM, McGrath, Justin M
wrote: Hi Matt, It's been a while and I haven't heard from Mario. I tried a different email address I found on this CV, but didn't get a reply, and I can't find any contact information for Karsten Ahnert. Do you have other ideas about how to contact them, or could someone else step in as a maintainer?
Best wishes, Justin
Justin, I found Karsten’s email and CCed him here. Hopefully he is willing to merge: https://github.com/boostorg/odeint/pull/58. As for fostering libraries I am not familiar with the process, but would be willing to step in if we continue to get no response. Matt
participants (2)
-
Matt Borland
-
McGrath, Justin M