From 308d0cf53f4b7ad1750fb1efb42b908c8e336b9f Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 23 Oct 2015 20:31:12 +0200 Subject: GetSrvRecords: Make thread-safe Gbp-Dch: ignore --- apt-pkg/contrib/srvrec.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/srvrec.cc b/apt-pkg/contrib/srvrec.cc index 837f2c84e..9af282653 100644 --- a/apt-pkg/contrib/srvrec.cc +++ b/apt-pkg/contrib/srvrec.cc @@ -28,8 +28,13 @@ bool GetSrvRecords(std::string host, int port, std::vector &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 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()); -- cgit v1.2.3