diff options
author | Jeff Garzik <jgarzik@exmulti.com> | 2012-09-04 09:00:02 -0700 |
---|---|---|
committer | Jeff Garzik <jgarzik@exmulti.com> | 2012-09-04 09:00:02 -0700 |
commit | 2fd6f067dbc1cb7cdc812e8c0a7ac2128318e72e (patch) | |
tree | f9bb3c13f836be6d7d17460e40b77c5711393875 | |
parent | bec02998b48cb66b034bcba685e83ee184b14a60 (diff) | |
parent | 9c809094525fe9c1a39f455f31d1f10842773201 (diff) |
Merge pull request #1777 from laanwj/2012_09_eliminate_sprintf
Remove last occurrence of potentially insecure function sprintf
-rw-r--r-- | src/net.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/net.cpp b/src/net.cpp index 8e9c4f85f0..76e44a6cf8 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1020,9 +1020,7 @@ void ThreadMapPort2(void* parg) { printf("ThreadMapPort started\n"); - char port[6]; - sprintf(port, "%d", GetListenPort()); - + std::string port = strprintf("%d", GetListenPort()); const char * multicastif = 0; const char * minissdpdpath = 0; struct UPNPDev * devlist = 0; @@ -1065,23 +1063,23 @@ void ThreadMapPort2(void* parg) #ifndef UPNPDISCOVER_SUCCESS /* miniupnpc 1.5 */ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, - port, port, lanaddr, strDesc.c_str(), "TCP", 0); + port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0); #else /* miniupnpc 1.6 */ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, - port, port, lanaddr, strDesc.c_str(), "TCP", 0, "0"); + port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0, "0"); #endif if(r!=UPNPCOMMAND_SUCCESS) printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", - port, port, lanaddr, r, strupnperror(r)); + port.c_str(), port.c_str(), lanaddr, r, strupnperror(r)); else printf("UPnP Port Mapping successful.\n"); int i = 1; loop { if (fShutdown || !fUseUPnP) { - r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port, "TCP", 0); + r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0); printf("UPNP_DeletePortMapping() returned : %d\n", r); freeUPNPDevlist(devlist); devlist = 0; FreeUPNPUrls(&urls); @@ -1092,16 +1090,16 @@ void ThreadMapPort2(void* parg) #ifndef UPNPDISCOVER_SUCCESS /* miniupnpc 1.5 */ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, - port, port, lanaddr, strDesc.c_str(), "TCP", 0); + port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0); #else /* miniupnpc 1.6 */ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, - port, port, lanaddr, strDesc.c_str(), "TCP", 0, "0"); + port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0, "0"); #endif if(r!=UPNPCOMMAND_SUCCESS) printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", - port, port, lanaddr, r, strupnperror(r)); + port.c_str(), port.c_str(), lanaddr, r, strupnperror(r)); else printf("UPnP Port Mapping successful.\n");; } |