Просмотр исходного кода

GetSrvRecords: Make thread-safe

Gbp-Dch: ignore
Julian Andres Klode лет назад: 10
Родитель
Сommit
308d0cf53f
1 измененных файлов с 7 добавлено и 2 удалено
  1. 7 2
      apt-pkg/contrib/srvrec.cc

+ 7 - 2
apt-pkg/contrib/srvrec.cc

@@ -28,8 +28,13 @@
 bool GetSrvRecords(std::string host, int port, std::vector<SrvRec> &Result)
 {
    std::string target;
-   struct servent *s_ent = getservbyport(htons(port), "tcp");
-   if (s_ent == NULL)
+   int res;
+   struct servent s_ent_buf;
+   struct servent *s_ent = nullptr;
+   std::vector<char> buf(1024);
+
+   res = getservbyport_r(htons(port), "tcp", &s_ent_buf, buf.data(), buf.size(), &s_ent);
+   if (res != 0 || s_ent == nullptr)
       return false;
 
    strprintf(target, "_%s._tcp.%s", s_ent->s_name, host.c_str());