summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/res_debug.c
diff options
context:
space:
mode:
authormarc <>2003-01-28 04:58:00 +0000
committermarc <>2003-01-28 04:58:00 +0000
commit547ebab319b228b064cf5dcb3ff0ae1bf23d24a2 (patch)
treef57454716593fb3b68672505c6dccab6438498f1 /src/lib/libc/net/res_debug.c
parent98a78d57b176408b5aca87705f9681c5b155b47c (diff)
downloadopenbsd-547ebab319b228b064cf5dcb3ff0ae1bf23d24a2.tar.gz
openbsd-547ebab319b228b064cf5dcb3ff0ae1bf23d24a2.tar.bz2
openbsd-547ebab319b228b064cf5dcb3ff0ae1bf23d24a2.zip
thread safer libc (note: safer, not safe)
Access to the global _res structure replaced by pointers to a per thread instance. If unthreaded the pointer is to the global structure. Also replaced a 64k stack array with malloc-ed memory so threaded aps (with a default 64k stack) have a chance at working. ok deraadt@
Diffstat (limited to 'src/lib/libc/net/res_debug.c')
-rw-r--r--src/lib/libc/net/res_debug.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/lib/libc/net/res_debug.c b/src/lib/libc/net/res_debug.c
index 2ea9173fe9..f4e4c271ed 100644
--- a/src/lib/libc/net/res_debug.c
+++ b/src/lib/libc/net/res_debug.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: res_debug.c,v 1.14 2002/07/25 21:55:30 deraadt Exp $ */ 1/* $OpenBSD: res_debug.c,v 1.15 2003/01/28 04:58:00 marc Exp $ */
2 2
3/* 3/*
4 * ++Copyright++ 1985, 1990, 1993 4 * ++Copyright++ 1985, 1990, 1993
@@ -82,7 +82,7 @@
82static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; 82static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
83static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $"; 83static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $";
84#else 84#else
85static char rcsid[] = "$OpenBSD: res_debug.c,v 1.14 2002/07/25 21:55:30 deraadt Exp $"; 85static char rcsid[] = "$OpenBSD: res_debug.c,v 1.15 2003/01/28 04:58:00 marc Exp $";
86#endif 86#endif
87#endif /* LIBC_SCCS and not lint */ 87#endif /* LIBC_SCCS and not lint */
88 88
@@ -102,6 +102,8 @@ static char rcsid[] = "$OpenBSD: res_debug.c,v 1.14 2002/07/25 21:55:30 deraadt
102#include <stdlib.h> 102#include <stdlib.h>
103#include <string.h> 103#include <string.h>
104 104
105#include "thread_private.h"
106
105extern const char *_res_opcodes[]; 107extern const char *_res_opcodes[];
106extern const char *_res_resultcodes[]; 108extern const char *_res_resultcodes[];
107 109
@@ -200,19 +202,20 @@ do_rrset(msg, len, cp, cnt, pflag, file, hs)
200 const char *hs; 202 const char *hs;
201 FILE *file; 203 FILE *file;
202{ 204{
205 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
203 int n; 206 int n;
204 int sflag; 207 int sflag;
205 208
206 /* 209 /*
207 * Print answer records. 210 * Print answer records.
208 */ 211 */
209 sflag = (_res.pfcode & pflag); 212 sflag = (_resp->pfcode & pflag);
210 if ((n = ntohs(cnt))) { 213 if ((n = ntohs(cnt))) {
211 if ((!_res.pfcode) || 214 if ((!_resp->pfcode) ||
212 ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) 215 ((sflag) && (_resp->pfcode & RES_PRF_HEAD1)))
213 fprintf(file, "%s", hs); 216 fprintf(file, "%s", hs);
214 while (--n >= 0) { 217 while (--n >= 0) {
215 if ((!_res.pfcode) || sflag) { 218 if ((!_resp->pfcode) || sflag) {
216 cp = p_rr(cp, msg, file); 219 cp = p_rr(cp, msg, file);
217 } else { 220 } else {
218 unsigned int dlen; 221 unsigned int dlen;
@@ -227,8 +230,8 @@ do_rrset(msg, len, cp, cnt, pflag, file, hs)
227 if ((cp - msg) > len) 230 if ((cp - msg) > len)
228 return (NULL); 231 return (NULL);
229 } 232 }
230 if ((!_res.pfcode) || 233 if ((!_resp->pfcode) ||
231 ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) 234 ((sflag) && (_resp->pfcode & RES_PRF_HEAD1)))
232 putc('\n', file); 235 putc('\n', file);
233 } 236 }
234 return (cp); 237 return (cp);
@@ -271,11 +274,12 @@ __fp_nquery(msg, len, file)
271 int len; 274 int len;
272 FILE *file; 275 FILE *file;
273{ 276{
277 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
274 register const u_char *cp, *endMark; 278 register const u_char *cp, *endMark;
275 register const HEADER *hp; 279 register const HEADER *hp;
276 register int n; 280 register int n;
277 281
278 if ((_res.options & RES_INIT) == 0 && res_init() == -1) 282 if ((_resp->options & RES_INIT) == 0 && res_init() == -1)
279 return; 283 return;
280 284
281#define TruncTest(x) if (x > endMark) goto trunc 285#define TruncTest(x) if (x > endMark) goto trunc
@@ -287,16 +291,16 @@ __fp_nquery(msg, len, file)
287 hp = (HEADER *)msg; 291 hp = (HEADER *)msg;
288 cp = msg + HFIXEDSZ; 292 cp = msg + HFIXEDSZ;
289 endMark = msg + len; 293 endMark = msg + len;
290 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || hp->rcode) { 294 if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_HEADX) || hp->rcode) {
291 fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %u", 295 fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %u",
292 _res_opcodes[hp->opcode], 296 _res_opcodes[hp->opcode],
293 _res_resultcodes[hp->rcode], 297 _res_resultcodes[hp->rcode],
294 ntohs(hp->id)); 298 ntohs(hp->id));
295 putc('\n', file); 299 putc('\n', file);
296 } 300 }
297 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX)) 301 if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_HEADX))
298 putc(';', file); 302 putc(';', file);
299 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) { 303 if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_HEAD2)) {
300 fprintf(file, "; flags:"); 304 fprintf(file, "; flags:");
301 if (hp->qr) 305 if (hp->qr)
302 fprintf(file, " qr"); 306 fprintf(file, " qr");
@@ -315,13 +319,13 @@ __fp_nquery(msg, len, file)
315 if (hp->cd) 319 if (hp->cd)
316 fprintf(file, " cd"); 320 fprintf(file, " cd");
317 } 321 }
318 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) { 322 if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_HEAD1)) {
319 fprintf(file, "; Ques: %u", ntohs(hp->qdcount)); 323 fprintf(file, "; Ques: %u", ntohs(hp->qdcount));
320 fprintf(file, ", Ans: %u", ntohs(hp->ancount)); 324 fprintf(file, ", Ans: %u", ntohs(hp->ancount));
321 fprintf(file, ", Auth: %u", ntohs(hp->nscount)); 325 fprintf(file, ", Auth: %u", ntohs(hp->nscount));
322 fprintf(file, ", Addit: %u", ntohs(hp->arcount)); 326 fprintf(file, ", Addit: %u", ntohs(hp->arcount));
323 } 327 }
324 if ((!_res.pfcode) || (_res.pfcode & 328 if ((!_resp->pfcode) || (_resp->pfcode &
325 (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) { 329 (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
326 putc('\n',file); 330 putc('\n',file);
327 } 331 }
@@ -329,13 +333,13 @@ __fp_nquery(msg, len, file)
329 * Print question records. 333 * Print question records.
330 */ 334 */
331 if ((n = ntohs(hp->qdcount))) { 335 if ((n = ntohs(hp->qdcount))) {
332 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) 336 if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_QUES))
333 fprintf(file, ";; QUESTIONS:\n"); 337 fprintf(file, ";; QUESTIONS:\n");
334 while (--n >= 0) { 338 while (--n >= 0) {
335 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) 339 if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_QUES))
336 fprintf(file, ";;\t"); 340 fprintf(file, ";;\t");
337 TruncTest(cp); 341 TruncTest(cp);
338 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) 342 if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_QUES))
339 cp = p_cdnname(cp, msg, len, file); 343 cp = p_cdnname(cp, msg, len, file);
340 else { 344 else {
341 int n; 345 int n;
@@ -349,16 +353,16 @@ __fp_nquery(msg, len, file)
349 } 353 }
350 ErrorTest(cp); 354 ErrorTest(cp);
351 TruncTest(cp); 355 TruncTest(cp);
352 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) 356 if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_QUES))
353 fprintf(file, ", type = %s", 357 fprintf(file, ", type = %s",
354 __p_type(_getshort((u_char*)cp))); 358 __p_type(_getshort((u_char*)cp)));
355 cp += INT16SZ; 359 cp += INT16SZ;
356 TruncTest(cp); 360 TruncTest(cp);
357 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) 361 if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_QUES))
358 fprintf(file, ", class = %s\n", 362 fprintf(file, ", class = %s\n",
359 __p_class(_getshort((u_char*)cp))); 363 __p_class(_getshort((u_char*)cp)));
360 cp += INT16SZ; 364 cp += INT16SZ;
361 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) 365 if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_QUES))
362 putc('\n', file); 366 putc('\n', file);
363 } 367 }
364 } 368 }
@@ -478,6 +482,7 @@ __p_rr(cp, msg, file)
478 const u_char *cp, *msg; 482 const u_char *cp, *msg;
479 FILE *file; 483 FILE *file;
480{ 484{
485 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
481 int type, class, dlen, n, c; 486 int type, class, dlen, n, c;
482 struct in_addr inaddr; 487 struct in_addr inaddr;
483 const u_char *cp1, *cp2; 488 const u_char *cp1, *cp2;
@@ -487,7 +492,7 @@ __p_rr(cp, msg, file)
487 char rrname[MAXDNAME]; /* The fqdn of this RR */ 492 char rrname[MAXDNAME]; /* The fqdn of this RR */
488 char base64_key[MAX_KEY_BASE64]; 493 char base64_key[MAX_KEY_BASE64];
489 494
490 if ((_res.options & RES_INIT) == 0 && res_init() == -1) { 495 if ((_resp->options & RES_INIT) == 0 && res_init() == -1) {
491 h_errno = NETDB_INTERNAL; 496 h_errno = NETDB_INTERNAL;
492 return (NULL); 497 return (NULL);
493 } 498 }
@@ -505,9 +510,9 @@ __p_rr(cp, msg, file)
505 dlen = _getshort((u_char*)cp); 510 dlen = _getshort((u_char*)cp);
506 cp += INT16SZ; 511 cp += INT16SZ;
507 cp1 = cp; 512 cp1 = cp;
508 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_TTLID)) 513 if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_TTLID))
509 fprintf(file, "\t%lu", (u_long)tmpttl); 514 fprintf(file, "\t%lu", (u_long)tmpttl);
510 if ((!_res.pfcode) || (_res.pfcode & RES_PRF_CLASS)) 515 if ((!_resp->pfcode) || (_resp->pfcode & RES_PRF_CLASS))
511 fprintf(file, "\t%s", __p_class(class)); 516 fprintf(file, "\t%s", __p_class(class));
512 fprintf(file, "\t%s", __p_type(type)); 517 fprintf(file, "\t%s", __p_type(type));
513 /* 518 /*