1 /*
2 * Functions for testing of string routines arguments.
3 *
4 * Copyright 2020 by Gray Watson
5 *
6 * This file is part of the dmalloc package.
7 *
8 * Permission to use, copy, modify, and distribute this software for
9 * any purpose and without fee is hereby granted, provided that the
10 * above copyright notice and this permission notice appear in all
11 * copies, and that the name of Gray Watson not be used in advertising
12 * or publicity pertaining to distribution of the document or software
13 * without specific, written prior permission.
14 *
15 * Gray Watson makes no representations about the suitability of the
16 * software described herein for any purpose. It is provided "as is"
17 * without express or implied warranty.
18 *
19 * The author may be contacted via http://dmalloc.com/
20 */
21
22 /*
23 * This file contains functions to be used to verify the arguments of
24 * string functions. If enabled these can discover problems with
25 * heap-based strings (such as fence errors) much closer to the error.
26 */
27
28 #define DMALLOC_DISABLE
29
30 #if HAVE_STRING_H
31 # include <string.h>
32 #endif
33 #if HAVE_STRINGS_H
34 # include <strings.h>
35 #endif
36 #if HAVE_STDLIB_H
37 # include <stdlib.h>
38 #endif
39
40 #include "conf.h"
41 #include "dmalloc.h"
42
43 #include "chunk.h"
44 #include "debug_tok.h"
45 #include "error.h"
46 #include "dmalloc_loc.h"
47 #include "arg_check.h"
48
49 /*
50 * Dummy function for checking strlen's arguments.
51 */
loc_strlen(const char * file,const int line,const char * func,const char * str)52 static int loc_strlen(const char *file, const int line,
53 const char *func, const char *str)
54 {
55 int len = 0;
56 const char *str_p;
57
58 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
59 if (! dmalloc_verify_pnt(file, line, func, str, 0 /* not exact */, -1)) {
60 dmalloc_message("bad pointer argument found in %s", func);
61 }
62 }
63
64 for (str_p = str; *str_p != '\0'; str_p++) {
65 len++;
66 }
67
68 return len;
69 }
70
71 #if HAVE_ATOI
72 /*
73 * Dummy function for checking atoi's arguments.
74 */
_dmalloc_atoi(const char * file,const int line,const char * str)75 int _dmalloc_atoi(const char *file, const int line, const char *str)
76 {
77 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
78 if (! dmalloc_verify_pnt(file, line, "atoi", str,
79 0 /* not exact */, -1)) {
80 dmalloc_message("bad pointer argument found in atoi");
81 }
82 }
83 return atoi(str);
84 }
85 #endif /* HAVE_ATOI */
86
87 #if HAVE_ATOL
88 /*
89 * Dummy function for checking atol's arguments.
90 */
_dmalloc_atol(const char * file,const int line,const char * str)91 long _dmalloc_atol(const char *file, const int line, const char *str)
92 {
93 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
94 if (! dmalloc_verify_pnt(file, line, "atol", str,
95 0 /* not exact */, -1)) {
96 dmalloc_message("bad pointer argument found in atol");
97 }
98 }
99 return atol(str);
100 }
101 #endif /* HAVE_ATOL */
102
103 #if HAVE_BCMP
104 /*
105 * Dummy function for checking bcmp's arguments.
106 */
_dmalloc_bcmp(const char * file,const int line,const void * b1,const void * b2,const DMALLOC_SIZE len)107 int _dmalloc_bcmp(const char *file, const int line,
108 const void *b1, const void *b2, const DMALLOC_SIZE len)
109 {
110 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
111 if ((! dmalloc_verify_pnt(file, line, "bcmp", b1,
112 0 /* not exact */, len))
113 || (! dmalloc_verify_pnt(file, line, "bcmp", b2,
114 0 /* not exact */, len))) {
115 dmalloc_message("bad pointer argument found in bcmp");
116 }
117 }
118 return bcmp(b1, b2, len);
119 }
120 #endif /* HAVE_BCMP */
121
122 #if HAVE_BCOPY
123 /*
124 * Dummy function for checking bcopy's arguments.
125 */
_dmalloc_bcopy(const char * file,const int line,const void * from,void * to,const DMALLOC_SIZE len)126 void _dmalloc_bcopy(const char *file, const int line,
127 const void *from, void *to, const DMALLOC_SIZE len)
128 {
129 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
130 if ((! dmalloc_verify_pnt(file, line, "bcopy", from,
131 0 /* not exact */, len))
132 || (! dmalloc_verify_pnt(file, line, "bcopy", to,
133 0 /* not exact */, len))) {
134 dmalloc_message("bad pointer argument found in bcopy");
135 }
136 }
137 bcopy(from, to, len);
138 }
139 #endif /* HAVE_BCOPY */
140
141 #if HAVE_BZERO
142 /*
143 * Dummy function for checking bzero's arguments.
144 */
_dmalloc_bzero(const char * file,const int line,void * buf,const DMALLOC_SIZE len)145 void _dmalloc_bzero(const char *file, const int line,
146 void *buf, const DMALLOC_SIZE len)
147 {
148 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
149 if (! dmalloc_verify_pnt(file, line, "bzero", buf,
150 0 /* not exact */, len)) {
151 dmalloc_message("bad pointer argument found in bzero");
152 }
153 }
154 bzero(buf, len);
155 }
156 #endif /* HAVE_BZERO */
157
158 #if HAVE_INDEX
159 /*
160 * Dummy function for checking index's arguments.
161 */
_dmalloc_index(const char * file,const int line,const char * str,const char ch)162 char *_dmalloc_index(const char *file, const int line,
163 const char *str, const char ch)
164 {
165 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
166 if (! dmalloc_verify_pnt(file, line, "index", str,
167 0 /* not exact */, -1)) {
168 dmalloc_message("bad pointer argument found in index");
169 }
170 }
171 return (char *)index(str, ch);
172 }
173 #endif /* HAVE_INDEX */
174
175 #if HAVE_MEMCCPY
176 /*
177 * Dummy function for checking memccpy's arguments.
178 */
_dmalloc_memccpy(const char * file,const int line,void * dest,const void * src,const int ch,const DMALLOC_SIZE len)179 void *_dmalloc_memccpy(const char *file, const int line,
180 void *dest, const void *src, const int ch,
181 const DMALLOC_SIZE len)
182 {
183 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
184 const char *src_p;
185 int min_size;
186
187 /* so we have to figure out the max length of the buffer directly here */
188 for (src_p = (char *)src; src_p < (char *)src + len; src_p++) {
189 if (*src_p == ch) {
190 src_p++;
191 break;
192 }
193 }
194 min_size = src_p - (char *)src;
195
196 /* maybe len maybe first ch */
197 if ((! dmalloc_verify_pnt(file, line, "memccpy", dest,
198 0 /* not exact */, min_size))
199 || (! dmalloc_verify_pnt(file, line, "memccpy", src,
200 0 /* not exact */, min_size))) {
201 dmalloc_message("bad pointer argument found in memccpy");
202 }
203 }
204 return (void *)memccpy(dest, src, ch, len);
205 }
206 #endif /* HAVE_MEMCCPY */
207
208 #if HAVE_MEMCHR
209 /*
210 * Dummy function for checking memchr's arguments.
211 */
_dmalloc_memchr(const char * file,const int line,const void * s1,const int ch,const DMALLOC_SIZE len)212 void *_dmalloc_memchr(const char *file, const int line,
213 const void *s1, const int ch, const DMALLOC_SIZE len)
214 {
215 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
216 if (! dmalloc_verify_pnt(file, line, "memchr", s1,
217 0 /* not exact */, len)) {
218 dmalloc_message("bad pointer argument found in memchr");
219 }
220 }
221 return (void *)memchr(s1, ch, len);
222 }
223 #endif /* HAVE_MEMCHR */
224
225 #if HAVE_MEMCMP
226 /*
227 * Dummy function for checking memcmp's arguments.
228 */
_dmalloc_memcmp(const char * file,const int line,const void * b1,const void * b2,const DMALLOC_SIZE len)229 int _dmalloc_memcmp(const char *file, const int line,
230 const void *b1, const void *b2, const DMALLOC_SIZE len)
231 {
232 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
233 if ((! dmalloc_verify_pnt(file, line, "memcmp", b1,
234 0 /* not exact */, len))
235 || (! dmalloc_verify_pnt(file, line, "memcmp", b2,
236 0 /* not exact */, len))) {
237 dmalloc_message("bad pointer argument found in memcmp");
238 }
239 }
240 return memcmp(b1, b2, len);
241 }
242 #endif /* HAVE_MEMCMP */
243
244 #if HAVE_MEMCPY
245 /*
246 * Dummy function for checking memcpy's arguments.
247 */
_dmalloc_memcpy(const char * file,const int line,void * to,const void * from,const DMALLOC_SIZE len)248 void *_dmalloc_memcpy(const char *file, const int line,
249 void *to, const void *from, const DMALLOC_SIZE len)
250 {
251 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
252 if ((! dmalloc_verify_pnt(file, line, "memcpy", to,
253 0 /* not exact */, len))
254 || (! dmalloc_verify_pnt(file, line, "memcpy", from,
255 0 /* not exact */, len))) {
256 dmalloc_message("bad pointer argument found in memcpy");
257 }
258
259 #if HAVE_MEMMOVE
260 /*
261 * If memmove exists, dump out a warning if memcpy is being used
262 * for overlapping memory segments.
263 */
264 if (((char *)from < (char *)to && (char *)from + len > (char *)to)
265 || ((char *)to < (char *)from && (char *)to + len > (char *)from)) {
266 dmalloc_message("%s:%d: WARNING: memory overlap in memcpy, should use memmove",
267 file, line);
268 }
269 #endif
270 }
271 return (void *)memcpy(to, from, len);
272 }
273 #endif /* HAVE_MEMCPY */
274
275 #if HAVE_MEMMOVE
276 /*
277 * Dummy function for checking memmove's arguments.
278 */
_dmalloc_memmove(const char * file,const int line,void * to,const void * from,const DMALLOC_SIZE len)279 void *_dmalloc_memmove(const char *file, const int line,
280 void *to, const void *from, const DMALLOC_SIZE len)
281 {
282 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
283 if ((! dmalloc_verify_pnt(file, line, "memmove", to,
284 0 /* not exact */, len))
285 || (! dmalloc_verify_pnt(file, line, "memmove", from,
286 0 /* not exact */, len))) {
287 dmalloc_message("bad pointer argument found in memmove");
288 }
289 }
290 return (void *)memmove(to, from, len);
291 }
292 #endif /* HAVE_MEMMOVE */
293
294 #if HAVE_MEMSET
295 /*
296 * Dummy function for checking memset's arguments.
297 */
_dmalloc_memset(const char * file,const int line,void * buf,const int ch,const DMALLOC_SIZE len)298 void *_dmalloc_memset(const char *file, const int line, void *buf,
299 const int ch, const DMALLOC_SIZE len)
300 {
301 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
302 if (! dmalloc_verify_pnt(file, line, "memset", buf,
303 0 /* not exact */, len)) {
304 dmalloc_message("bad pointer argument found in memset");
305 }
306 }
307 return (void *)memset(buf, ch, len);
308 }
309 #endif /* HAVE_MEMSET */
310
311 #if HAVE_RINDEX
312 /*
313 * Dummy function for checking rindex's arguments.
314 */
_dmalloc_rindex(const char * file,const int line,const char * str,const char ch)315 char *_dmalloc_rindex(const char *file, const int line,
316 const char *str, const char ch)
317 {
318 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
319 if (! dmalloc_verify_pnt(file, line, "rindex", str,
320 0 /* not exact */, -1)) {
321 dmalloc_message("bad pointer argument found in rindex");
322 }
323 }
324 return (char *)rindex(str, ch);
325 }
326 #endif /* HAVE_RINDEX */
327
328 #if HAVE_STRCASECMP
329 /*
330 * Dummy function for checking strcasecmp's arguments.
331 */
_dmalloc_strcasecmp(const char * file,const int line,const char * s1,const char * s2)332 int _dmalloc_strcasecmp(const char *file, const int line,
333 const char *s1, const char *s2)
334 {
335 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
336 if ((! dmalloc_verify_pnt(file, line, "strcasecmp", s1,
337 0 /* not exact */, -1))
338 || (! dmalloc_verify_pnt(file, line, "strcasecmp", s2,
339 0 /* not exact */, -1))) {
340 dmalloc_message("bad pointer argument found in strcasecmp");
341 }
342 }
343 return strcasecmp(s1, s2);
344 }
345 #endif /* HAVE_STRCASECMP */
346
347 #if HAVE_STRCAT
348 /*
349 * Dummy function for checking strcat's arguments.
350 */
_dmalloc_strcat(const char * file,const int line,char * to,const char * from)351 char *_dmalloc_strcat(const char *file, const int line,
352 char *to, const char *from)
353 {
354 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
355 if ((! dmalloc_verify_pnt(file, line, "strcat", to,
356 0 /* not exact */,
357 loc_strlen(file, line, "strcat", to)
358 + loc_strlen(file, line, "strcat", from) + 1))
359 || (! dmalloc_verify_pnt(file, line, "strcat", from,
360 0 /* not exact */, -1))) {
361 dmalloc_message("bad pointer argument found in strcat");
362 }
363 }
364 return (char *)strcat(to, from);
365 }
366 #endif /* HAVE_STRCAT */
367
368 #if HAVE_STRCHR
369 /*
370 * Dummy function for checking strchr's arguments.
371 */
_dmalloc_strchr(const char * file,const int line,const char * str,const int ch)372 char *_dmalloc_strchr(const char *file, const int line,
373 const char *str, const int ch)
374 {
375 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
376 if (! dmalloc_verify_pnt(file, line, "strchr", str,
377 0 /* not exact */, -1)) {
378 dmalloc_message("bad pointer argument found in strchr");
379 }
380 }
381 return (char *)strchr(str, ch);
382 }
383 #endif /* HAVE_STRCHR */
384
385 #if HAVE_STRCMP
386 /*
387 * Dummy function for checking strcmp's arguments.
388 */
_dmalloc_strcmp(const char * file,const int line,const char * s1,const char * s2)389 int _dmalloc_strcmp(const char *file, const int line,
390 const char *s1, const char *s2)
391 {
392 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
393 if ((! dmalloc_verify_pnt(file, line, "strcmp", s1,
394 0 /* not exact */, -1))
395 || (! dmalloc_verify_pnt(file, line, "strcmp", s2,
396 0 /* not exact */, -1))) {
397 dmalloc_message("bad pointer argument found in strcmp");
398 }
399 }
400 return strcmp(s1, s2);
401 }
402 #endif /* HAVE_STRCMP */
403
404 #if HAVE_STRCPY
405 /*
406 * Dummy function for checking strcpy's arguments.
407 */
_dmalloc_strcpy(const char * file,const int line,char * to,const char * from)408 char *_dmalloc_strcpy(const char *file, const int line,
409 char *to, const char *from)
410 {
411 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
412 if ((! dmalloc_verify_pnt(file, line, "strcpy", to,
413 0 /* not exact */,
414 loc_strlen(file, line, "strcpy", from) + 1))
415 || (! dmalloc_verify_pnt(file, line, "strcpy", from,
416 0 /* not exact */, -1))) {
417 dmalloc_message("bad pointer argument found in strcpy");
418 }
419 }
420 return (char *)strcpy(to, from);
421 }
422 #endif /* HAVE_STRCPY */
423
424 #if HAVE_STRCSPN
425 /*
426 * Dummy function for checking strcspn's arguments.
427 */
_dmalloc_strcspn(const char * file,const int line,const char * str,const char * list)428 int _dmalloc_strcspn(const char *file, const int line,
429 const char *str, const char *list)
430 {
431 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
432 if ((! dmalloc_verify_pnt(file, line, "strcspn", str,
433 0 /* not exact */, -1))
434 || (! dmalloc_verify_pnt(file, line, "strcspn", list,
435 0 /* not exact */, -1))) {
436 dmalloc_message("bad pointer argument found in strcspn");
437 }
438 }
439 return strcspn(str, list);
440 }
441 #endif /* HAVE_STRCSPN */
442
443 #if HAVE_STRLEN
444 /*
445 * Dummy function for checking strlen's arguments.
446 */
_dmalloc_strlen(const char * file,const int line,const char * str)447 DMALLOC_SIZE _dmalloc_strlen(const char *file, const int line,
448 const char *str)
449 {
450 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
451 if (! dmalloc_verify_pnt(file, line, "strlen", str,
452 0 /* not exact */, -1)) {
453 dmalloc_message("bad pointer argument found in strlen");
454 }
455 }
456
457 return loc_strlen(file, line, "strlen", str);
458 }
459 #endif
460
461 #if HAVE_STRNCASECMP
462 /*
463 * Dummy function for checking strncasecmp's arguments.
464 */
_dmalloc_strncasecmp(const char * file,const int line,const char * s1,const char * s2,const DMALLOC_SIZE len)465 int _dmalloc_strncasecmp(const char *file, const int line,
466 const char *s1, const char *s2,
467 const DMALLOC_SIZE len)
468 {
469 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
470 const char *s1_p, *s2_p;
471 int min_size;
472
473 /* we go through both pointers up to the length characters */
474 for (s1_p = s1, s2_p = s2; s1_p < s1 + len; s1_p++, s2_p++) {
475 if (*s1_p == '\0' || *s2_p == '\0') {
476 s1_p++;
477 break;
478 }
479 }
480 min_size = s1_p - s1;
481
482 if ((! dmalloc_verify_pnt(file, line, "strncasecmp", s1,
483 0 /* not exact */, min_size))
484 || (! dmalloc_verify_pnt(file, line, "strncasecmp", s2,
485 0 /* not exact */, min_size))) {
486 dmalloc_message("bad pointer argument found in strncasecmp");
487 }
488 }
489 return strncasecmp(s1, s2, len);
490 }
491 #endif /* HAVE_STRNCASECMP */
492
493 #if HAVE_STRNCAT
494 /*
495 * Dummy function for checking strncat's arguments.
496 */
_dmalloc_strncat(const char * file,const int line,char * to,const char * from,const DMALLOC_SIZE len)497 char *_dmalloc_strncat(const char *file, const int line,
498 char *to, const char *from, const DMALLOC_SIZE len)
499 {
500 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
501 const char *from_p;
502 int min_size;
503
504 /* so we have to figure out the max length of the buffers directly here */
505 for (from_p = from; from_p < from + len; from_p++) {
506 if (*from_p == '\0') {
507 /* no need to do ++ here because we +1 for the \0 anyway */
508 break;
509 }
510 }
511 min_size = from_p - from;
512
513 /* either len or nullc */
514 if ((! dmalloc_verify_pnt(file, line, "strncat", to,
515 0 /* not exact */,
516 loc_strlen(file, line, "strncat", to) + min_size
517 + 1))
518 || (! dmalloc_verify_pnt(file, line, "strncat", from,
519 0 /* not exact */, min_size))) {
520 dmalloc_message("bad pointer argument found in strncat");
521 }
522 }
523 return (char *)strncat(to, from, len);
524 }
525 #endif /* HAVE_STRNCAT */
526
527 #if HAVE_STRNCMP
528 /*
529 * Dummy function for checking strncmp's arguments.
530 */
_dmalloc_strncmp(const char * file,const int line,const char * s1,const char * s2,const DMALLOC_SIZE len)531 int _dmalloc_strncmp(const char *file, const int line,
532 const char *s1, const char *s2,
533 const DMALLOC_SIZE len)
534 {
535 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
536 const char *s1_p, *s2_p;
537 int min_size;
538
539 /* so we have to figure out the max length of the buffers directly here */
540 for (s1_p = s1, s2_p = s2; s1_p < s1 + len; s1_p++, s2_p++) {
541 if (*s1_p == '\0' || *s2_p == '\0') {
542 s1_p++;
543 break;
544 }
545 }
546 min_size = s1_p - s1;
547
548 /* either len or nullc */
549 if ((! dmalloc_verify_pnt(file, line, "strncmp", s1,
550 0 /* not exact */, min_size))
551 || (! dmalloc_verify_pnt(file, line, "strncmp", s2,
552 0 /* not exact */, min_size))) {
553 dmalloc_message("bad pointer argument found in strncmp");
554 }
555 }
556 return strncmp(s1, s2, len);
557 }
558 #endif /* HAVE_STRNCMP */
559
560 #if HAVE_STRNCPY
561 /*
562 * Dummy function for checking strncpy's arguments.
563 */
_dmalloc_strncpy(const char * file,const int line,char * to,const char * from,const DMALLOC_SIZE len)564 char *_dmalloc_strncpy(const char *file, const int line,
565 char *to, const char *from, const DMALLOC_SIZE len)
566 {
567 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
568 const char *from_p;
569 int min_size;
570
571 /* so we have to figure out the max length of the buffers directly here */
572 for (from_p = from; from_p < from + len; from_p++) {
573 if (*from_p == '\0') {
574 from_p++;
575 break;
576 }
577 }
578 min_size = from_p - from;
579
580 /* len or until nullc */
581 if ((! dmalloc_verify_pnt(file, line, "strncpy", to,
582 0 /* not exact */, min_size))
583 || (! dmalloc_verify_pnt(file, line, "strncpy", from,
584 0 /* not exact */, min_size))) {
585 dmalloc_message("bad pointer argument found in strncpy");
586 }
587 }
588 return (char *)strncpy(to, from, len);
589 }
590 #endif /* HAVE_STRNCPY */
591
592 #if HAVE_STRPBRK
593 /*
594 * Dummy function for checking strpbrk's arguments.
595 */
_dmalloc_strpbrk(const char * file,const int line,const char * str,const char * list)596 char *_dmalloc_strpbrk(const char *file, const int line,
597 const char *str, const char *list)
598 {
599 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
600 if ((! dmalloc_verify_pnt(file, line, "strpbrk", str,
601 0 /* not exact */, -1))
602 || (! dmalloc_verify_pnt(file, line, "strpbrk", list,
603 0 /* not exact */, -1))) {
604 dmalloc_message("bad pointer argument found in strpbrk");
605 }
606 }
607 return (char *)strpbrk(str, list);
608 }
609 #endif /* HAVE_STRPBRK */
610
611 #if HAVE_STRRCHR
612 /*
613 * Dummy function for checking strrchr's arguments.
614 */
_dmalloc_strrchr(const char * file,const int line,const char * str,const int ch)615 char *_dmalloc_strrchr(const char *file, const int line,
616 const char *str, const int ch)
617 {
618 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
619 if (! dmalloc_verify_pnt(file, line, "strrchr", str,
620 0 /* not exact */, -1)) {
621 dmalloc_message("bad pointer argument found in strrchr");
622 }
623 }
624 return (char *)strrchr(str, ch);
625 }
626 #endif /* HAVE_STRRCHR */
627
628 #if HAVE_STRSPN
629 /*
630 * Dummy function for checking strspn's arguments.
631 */
_dmalloc_strspn(const char * file,const int line,const char * str,const char * list)632 int _dmalloc_strspn(const char *file, const int line,
633 const char *str, const char *list)
634 {
635 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
636 if ((! dmalloc_verify_pnt(file, line, "strspn", str,
637 0 /* not exact */, -1))
638 || (! dmalloc_verify_pnt(file, line, "strspn", list,
639 0 /* not exact */, -1))) {
640 dmalloc_message("bad pointer argument found in strspn");
641 }
642 }
643 return strspn(str, list);
644 }
645 #endif /* HAVE_STRSPN */
646
647 #if HAVE_STRSTR
648 /*
649 * Dummy function for checking strstr's arguments.
650 */
_dmalloc_strstr(const char * file,const int line,const char * str,const char * pat)651 char *_dmalloc_strstr(const char *file, const int line,
652 const char *str, const char *pat)
653 {
654 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
655 if ((! dmalloc_verify_pnt(file, line, "strstr", str,
656 0 /* not exact */, -1))
657 || (! dmalloc_verify_pnt(file, line, "strstr", pat,
658 0 /* not exact */, -1))) {
659 dmalloc_message("bad pointer argument found in strstr");
660 }
661 }
662 return (char *)strstr(str, pat);
663 }
664 #endif /* HAVE_STRSTR */
665
666 #if HAVE_STRTOK
667 /*
668 * Dummy function for checking strtok's arguments.
669 */
_dmalloc_strtok(const char * file,const int line,char * str,const char * sep)670 char *_dmalloc_strtok(const char *file, const int line,
671 char *str, const char *sep)
672 {
673 if (BIT_IS_SET(_dmalloc_flags, DMALLOC_DEBUG_CHECK_FUNCS)) {
674 if ((str != NULL
675 && (! dmalloc_verify_pnt(file, line, "strtok", str,
676 0 /* not exact */, -1)))
677 || (! dmalloc_verify_pnt(file, line, "strtok", sep,
678 0 /* not exact */, -1))) {
679 dmalloc_message("bad pointer argument found in strtok");
680 }
681 }
682 return (char *)strtok(str, sep);
683 }
684 #endif /* HAVE_STRTOK */
685