View | Details | Raw Unified | Return to bug 2608 | Differences between
and this patch

Collapse All | Expand All

(-)a/openbsd-compat/strlcat.c (-3 / +7 lines)
Lines 23-28 Link Here
23
23
24
#include <sys/types.h>
24
#include <sys/types.h>
25
#include <string.h>
25
#include <string.h>
26
#include <stdint.h>
26
27
27
/*
28
/*
28
 * Appends src to string dst of size siz (unlike strncat, siz is the
29
 * Appends src to string dst of size siz (unlike strncat, siz is the
Lines 42-48 strlcat(char *dst, const char *src, size_t siz) Link Here
42
	/* Find the end of dst and adjust bytes left but don't go past end */
43
	/* Find the end of dst and adjust bytes left but don't go past end */
43
	while (n-- != 0 && *d != '\0')
44
	while (n-- != 0 && *d != '\0')
44
		d++;
45
		d++;
45
	dlen = d - dst;
46
	dlen = (uintptr_t)d - (uintptr_t)dst;
46
	n = siz - dlen;
47
	n = siz - dlen;
47
48
48
	if (n == 0)
49
	if (n == 0)
Lines 55-62 strlcat(char *dst, const char *src, size_t siz) Link Here
55
		s++;
56
		s++;
56
	}
57
	}
57
	*d = '\0';
58
	*d = '\0';
58
59
        /*
59
	return(dlen + (s - src));	/* count does not include NUL */
60
	 * Cast pointers to unsigned type before calculation, to avoid signed
61
	 * overflow when the string ends where the MSB has changed.
62
	 */
63
	return (dlen + ((uintptr_t)s - (uintptr_t)src));	/* count does not include NUL */
60
}
64
}
61
65
62
#endif /* !HAVE_STRLCAT */
66
#endif /* !HAVE_STRLCAT */
(-)a/openbsd-compat/strlcpy.c (-2 / +6 lines)
Lines 23-28 Link Here
23
23
24
#include <sys/types.h>
24
#include <sys/types.h>
25
#include <string.h>
25
#include <string.h>
26
#include <stdint.h>
26
27
27
/*
28
/*
28
 * Copy src to string dst of size siz.  At most siz-1 characters
29
 * Copy src to string dst of size siz.  At most siz-1 characters
Lines 51-58 strlcpy(char *dst, const char *src, size_t siz) Link Here
51
		while (*s++)
52
		while (*s++)
52
			;
53
			;
53
	}
54
	}
54
55
        /*
55
	return(s - src - 1);	/* count does not include NUL */
56
	 * Cast pointers to unsigned type before calculation, to avoid signed
57
	 * overflow when the string ends where the MSB has changed.
58
	 */
59
	return ((uintptr_t)s - (uintptr_t)src - 1);	/* count does not include NUL */
56
}
60
}
57
61
58
#endif /* !HAVE_STRLCPY */
62
#endif /* !HAVE_STRLCPY */
(-)a/openbsd-compat/strnlen.c (-3 / +6 lines)
Lines 23-28 Link Here
23
#include <sys/types.h>
23
#include <sys/types.h>
24
24
25
#include <string.h>
25
#include <string.h>
26
#include <stdint.h>
26
27
27
size_t
28
size_t
28
strnlen(const char *str, size_t maxlen)
29
strnlen(const char *str, size_t maxlen)
Lines 31-37 strnlen(const char *str, size_t maxlen) Link Here
31
32
32
	for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--)
33
	for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--)
33
		;
34
		;
34
35
        /*
35
	return (size_t)(cp - str);
36
	 * Cast pointers to unsigned type before calculation, to avoid signed
37
	 * overflow when the string ends where the MSB has changed.
38
	 */
39
	return (size_t)((uintptr_t)cp - (uintptr_t)str);
36
}
40
}
37
#endif
41
#endif
38
- 

Return to bug 2608