%d can return up to 11 characters (12 with \0). Move away from fixed buffer completely and use our own safe function strprintf.
I'm reasonably sure that this cannot be exploited due to earlier checks, but it does make me feel a tad uneasy.
%d can return up to 11 characters (12 with \0). Move away from fixed buffer completely and use our own safe function strprintf.
I'm reasonably sure that this cannot be exploited due to earlier checks, but it does make me feel a tad uneasy.
%d can return up to 11 characters. Move away from fixed buffer completely and
use our own safe function strprintf.
1062 | @@ -1065,23 +1063,23 @@ void ThreadMapPort2(void* parg) 1063 | #ifndef UPNPDISCOVER_SUCCESS 1064 | /* miniupnpc 1.5 */ 1065 | r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, 1066 | - port, port, lanaddr, strDesc.c_str(), "TCP", 0); 1067 | + port..c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0);
It seems you have a "." too much here.
Yep. Good catch.
1019 | @@ -1020,9 +1020,7 @@ void ThreadMapPort2(void* parg) 1020 | { 1021 | printf("ThreadMapPort started\n"); 1022 | 1023 | - char port[6]; 1024 | - sprintf(port, "%d", GetListenPort()); 1025 | - 1026 | + std::string port = strprintf("%d", GetListenPort());
I removed my former comment, but want to make another suggestion. Why not use?
#include <boost/lexical_cast.hpp>
std::string port = boost::lexical_cast<std::string>(GetListenPort());
http://www.boost.org/doc/libs/1_51_0/doc/html/boost_lexical_cast.html
That's possible, but I don't see the advantage. We don't use lexical_cast anywhere right now, and we have the strprintf function already.
You are right, I was just asking, if a own strprintf makes sense in that context, as I (but that is a pure feeling) would consider boost functions more safe than own string-handling code. I'm fine with leaving that pull as is anyway :).
Is it possible to remove the use of sprintf here, too? https://github.com/bitcoin/bitcoin/blob/master/src/uint256.h#L291
I thought I removed that sprintf months ago. At least I rewrote a similar function in util.cpp. That function should use the existing HexStr function.
Edit: I see the reason now. uint256.h cannot include util.h, as util.h includes uint256.h, So uint256 cannot simply use HexStr unless we move that to a third .h file...