Remove a bunch of warnings by eliminating deprecated functions.

This commit is contained in:
Adam Ierymenko 2025-08-21 10:06:56 -04:00
commit 3e21edb891
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
5 changed files with 19 additions and 19 deletions

13
one.cpp
View file

@ -1191,14 +1191,14 @@ static int cli(int argc, char** argv)
UInt8 path[PATH_MAX];
if (FSFindFolder(kUserDomain, kDesktopFolderType, kDontCreateFolder, &fsref) == noErr && FSRefMakePath(&fsref, path, sizeof(path)) == noErr) {}
else if (getenv("SUDO_USER")) {
sprintf((char*)path, "/Users/%s/Desktop", getenv("SUDO_USER"));
snprintf((char*)path, sizeof(path), "/Users/%s/Desktop", getenv("SUDO_USER"));
}
else {
fprintf(stdout, "%s", dump.str().c_str());
return 0;
}
sprintf((char*)path, "%s%szerotier_dump.txt", (char*)path, ZT_PATH_SEPARATOR_S);
snprintf((char*)path, sizeof(path), "%s%szerotier_dump.txt", (char*)path, ZT_PATH_SEPARATOR_S);
fprintf(stdout, "Writing dump to: %s\n", path);
int fd = open((char*)path, O_CREAT | O_RDWR, 0664);
@ -1235,8 +1235,9 @@ static int cli(int argc, char** argv)
dump << "MTU: " << curAddr->Mtu << ZT_EOL_S;
dump << "MAC: ";
char macBuffer[64] = {};
sprintf(
snprintf(
macBuffer,
sizeof(macBuffer),
"%02x:%02x:%02x:%02x:%02x:%02x",
curAddr->PhysicalAddress[0],
curAddr->PhysicalAddress[1],
@ -1271,7 +1272,7 @@ static int cli(int argc, char** argv)
char path[MAX_PATH + 1] = {};
if (SHGetFolderPathA(NULL, CSIDL_DESKTOP, NULL, 0, path) == S_OK) {
sprintf(path, "%s%szerotier_dump.txt", path, ZT_PATH_SEPARATOR_S);
snprintf(path, sizeof(path), "%s%szerotier_dump.txt", path, ZT_PATH_SEPARATOR_S);
fprintf(stdout, "Writing dump to: %s\n", path);
HANDLE file = CreateFileA(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == INVALID_HANDLE_VALUE) {
@ -1317,7 +1318,7 @@ static int cli(int argc, char** argv)
unsigned char mac_addr[6];
memcpy(mac_addr, ifr.ifr_hwaddr.sa_data, 6);
char macStr[18];
sprintf(macStr, "%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
dump << "MAC: " << macStr << ZT_EOL_S;
}
@ -1348,7 +1349,7 @@ static int cli(int argc, char** argv)
close(sock);
char cwd[16384];
getcwd(cwd, sizeof(cwd));
sprintf(cwd, "%s%szerotier_dump.txt", cwd, ZT_PATH_SEPARATOR_S);
snprintf(cwd, sizeof(cwd), "%s%szerotier_dump.txt", cwd, ZT_PATH_SEPARATOR_S);
fprintf(stdout, "Writing dump to: %s\n", cwd);
int fd = open(cwd, O_CREAT | O_RDWR, 0664);
if (fd == -1) {

View file

@ -53,7 +53,7 @@ void MacDNSHelper::setDNS(uint64_t nwid, const char *domain, const std::vector<I
&kCFTypeDictionaryValueCallBacks);
char buf[256] = {0};
sprintf(buf, "State:/Network/Service/%.16llx/DNS", nwid);
snprintf(buf, sizeof(buf), "State:/Network/Service/%.16llx/DNS", nwid);
CFStringRef key = CFStringCreateWithCString(NULL, buf, kCFStringEncodingUTF8);
CFArrayRef list = SCDynamicStoreCopyKeyList(ds, key);
CFIndex i = 0, j = CFArrayGetCount(list);
@ -97,7 +97,7 @@ void MacDNSHelper::removeDNS(uint64_t nwid)
SCDynamicStoreRef ds = SCDynamicStoreCreate(NULL, CFSTR("zerotier"), NULL, NULL);
char buf[256] = {0};
sprintf(buf, "State:/Network/Service/%.16llx/DNS", nwid);
snprintf(buf, sizeof(buf), "State:/Network/Service/%.16llx/DNS", nwid);
CFStringRef key = CFStringCreateWithCString(NULL, buf, kCFStringEncodingUTF8);
SCDynamicStoreRemoveValue(ds, key);
CFRelease(key);
@ -136,7 +136,7 @@ bool MacDNSHelper::addIps4(uint64_t nwid, const MAC mac, const char *dev, const
SCDynamicStoreRef ds = SCDynamicStoreCreate(NULL, CFSTR("zerotier"), NULL, NULL);
char buf[256] = { 0 };
sprintf(buf, "State:/Network/Service/%.16llx/IPv4", nwid);
snprintf(buf, sizeof(buf), "State:/Network/Service/%.16llx/IPv4", nwid);
CFStringRef key = CFStringCreateWithCString(NULL, buf, kCFStringEncodingUTF8);
@ -232,7 +232,7 @@ bool MacDNSHelper::addIps6(uint64_t nwid, const MAC mac, const char *dev, const
SCDynamicStoreRef ds = SCDynamicStoreCreate(NULL, CFSTR("zerotier"), NULL, NULL);
char buf[256] = { 0 };
sprintf(buf, "State:/Network/Service/%.16llx/IPv6", nwid);
snprintf(buf, sizeof(buf), "State:/Network/Service/%.16llx/IPv6", nwid);
InetAddress ll = InetAddress::makeIpv6LinkLocal(mac);
char buf2[256] = {0};
@ -327,7 +327,7 @@ bool MacDNSHelper::removeIps6(uint64_t nwid)
SCDynamicStoreRef ds = SCDynamicStoreCreate(NULL, CFSTR("zerotier"), NULL, NULL);
char buf[256] = {0};
sprintf(buf, "State:/Network/Service/%.16llx/IPv6", nwid);
snprintf(buf, sizeof(buf), "State:/Network/Service/%.16llx/IPv6", nwid);
CFStringRef key = CFStringCreateWithCString(NULL, buf, kCFStringEncodingUTF8);
bool res = SCDynamicStoreRemoveValue(ds, key);
CFRelease(key);
@ -342,7 +342,7 @@ bool MacDNSHelper::removeIps4(uint64_t nwid)
SCDynamicStoreRef ds = SCDynamicStoreCreate(NULL, CFSTR("zerotier"), NULL, NULL);
char buf[256] = {0};
sprintf(buf, "State:/Network/Service/%.16llx/IPv4", nwid);
snprintf(buf, sizeof(buf), "State:/Network/Service/%.16llx/IPv4", nwid);
CFStringRef key = CFStringCreateWithCString(NULL, buf, kCFStringEncodingUTF8);
bool res = SCDynamicStoreRemoveValue(ds, key);
CFRelease(key);

View file

@ -123,7 +123,7 @@ MacEthernetTap::MacEthernetTap(
args[1] = p->ifa_name;
args[2] = "destroy";
args[3] = (char*)0;
const pid_t pid = vfork();
const pid_t pid = fork();
if (pid == 0) {
execv(args[0], const_cast<char**>(args));
_exit(-1);
@ -255,7 +255,7 @@ MacEthernetTap::~MacEthernetTap()
args[1] = _dev.c_str();
args[2] = "destroy";
args[3] = (char*)0;
pid0 = vfork();
pid0 = fork();
if (pid0 == 0) {
execv(args[0], const_cast<char**>(args));
_exit(-1);
@ -266,7 +266,7 @@ MacEthernetTap::~MacEthernetTap()
args[1] = tmp;
// args[2] = "destroy";
// args[3] = (char *)0;
pid1 = vfork();
pid1 = fork();
if (pid1 == 0) {
execv(args[0], const_cast<char**>(args));
_exit(-1);

View file

@ -454,7 +454,7 @@ MacKextEthernetTap::~MacKextEthernetTap()
globalTapsRunning = 0; // sanity check -- should not be possible
char tmp[16384];
sprintf(tmp, "%s/%s", _homePath.c_str(), "tap.kext");
snprintf(tmp, sizeof(tmp), "%s/%s", _homePath.c_str(), "tap.kext");
long kextpid = (long)fork();
if (kextpid == 0) {
OSUtils::redirectUnixOutputs("/dev/null", (const char*)0);

View file

@ -1294,7 +1294,6 @@ class OneServiceImpl : public OneService {
_lastRestart = clockShouldBe;
int64_t lastTapMulticastGroupCheck = 0;
int64_t lastBindRefresh = 0;
int64_t lastUpdateCheck = clockShouldBe;
int64_t lastCleanedPeersDb = 0;
int64_t lastLocalConfFileCheck = OSUtils::now();
int64_t lastOnline = lastLocalConfFileCheck;
@ -1798,7 +1797,7 @@ class OneServiceImpl : public OneService {
if (match.matched) {
// fallback
char indexHtmlPath[16384];
sprintf(indexHtmlPath, "%s/%s/%s", appUiDir, match.str().c_str(), "index.html");
snprintf(indexHtmlPath, sizeof(indexHtmlPath), "%s/%s/%s", appUiDir, match.str().c_str(), "index.html");
// fprintf(stderr, "fallback path %s\n", indexHtmlPath);
std::string indexHtml;
@ -1822,7 +1821,7 @@ class OneServiceImpl : public OneService {
// add .html
std::string htmlFile;
char htmlPath[16384];
sprintf(htmlPath, "%s%s%s", appUiDir, (req.path).substr(appUiPath.length()).c_str(), ".html");
snprintf(htmlPath, sizeof(htmlPath), "%s%s%s", appUiDir, (req.path).substr(appUiPath.length()).c_str(), ".html");
// fprintf(stderr, "path: %s\n", htmlPath);
if (OSUtils::readFile(htmlPath, htmlFile)) {
res.set_content(htmlFile.c_str(), "text/html");