View | Details | Raw Unified | Return to bug 221323
Collapse All | Expand All

(-)b/lib/libc/stdlib/set_constraint_handler_s.c (-2 / +4 lines)
Lines 32-37 __FBSDID("$FreeBSD$"); Link Here
32
#include <errno.h>
32
#include <errno.h>
33
#include <pthread.h>
33
#include <pthread.h>
34
#include <stddef.h>
34
#include <stddef.h>
35
#include <stdio.h>
35
#include <stdlib.h>
36
#include <stdlib.h>
36
#include "un-namespace.h"
37
#include "un-namespace.h"
37
#include "libc_private.h"
38
#include "libc_private.h"
Lines 81-90 __throw_constraint_handler_s(const char * restrict msg, errno_t error) Link Here
81
}
82
}
82
83
83
void
84
void
84
abort_handler_s(const char * restrict msg __unused,
85
abort_handler_s(const char * restrict msg, void * restrict ptr __unused,
85
    void * restrict ptr __unused, errno_t error __unused)
86
    errno_t error __unused)
86
{
87
{
87
88
89
	(void) fprintf(stderr, "abort_handler_s : %s\n", msg);
88
	abort();
90
	abort();
89
}
91
}
90
92
(-)b/lib/libc/string/memset_s.c (-5 / +8 lines)
Lines 42-63 memset_s(void *s, rsize_t smax, int c, rsize_t n) Link Here
42
	volatile unsigned char *dst;
42
	volatile unsigned char *dst;
43
43
44
	ret = EINVAL;
44
	ret = EINVAL;
45
	lim = smax;
45
	lim = (n < smax) ? n : smax;
46
	v = (unsigned char)c;
46
	v = (unsigned char)c;
47
	dst = (unsigned char *)s;
47
	dst = (unsigned char *)s;
48
	if (s == NULL) {
48
	if (s == NULL) {
49
		__throw_constraint_handler_s("memset_s : s is NULL", ret);
49
		__throw_constraint_handler_s("memset_s : s is NULL", ret);
50
	} else if (smax > RSIZE_MAX) {
50
	} else if (smax > RSIZE_MAX) {
51
		__throw_constraint_handler_s("memset_s : smax > RSIZE_MAX",
51
		__throw_constraint_handler_s("memset_s : smax > RSIZE_MAX",
52
		     ret);
52
		    ret);
53
	} else if (n > RSIZE_MAX) {
53
	} else if (n > RSIZE_MAX) {
54
		__throw_constraint_handler_s("memset_s : n > RSIZE_MAX", ret);
54
		__throw_constraint_handler_s("memset_s : n > RSIZE_MAX", ret);
55
	} else {
55
	} else {
56
		if (n < smax)
57
			lim = n;
58
		while (lim > 0)
56
		while (lim > 0)
59
			dst[--lim] = v;
57
			dst[--lim] = v;
60
		ret = 0;
58
		if (n > smax) {
59
			__throw_constraint_handler_s("memset_s : n > smax",
60
			    ret);
61
		} else {
62
			ret = 0;
63
		}
61
	}
64
	}
62
	return (ret);
65
	return (ret);
63
}
66
}
(-)b/lib/libc/tests/string/memset_s_test.c (-2 / +7 lines)
Lines 109-121 ATF_TC_BODY(n_lt_smax, tc) Link Here
109
	assert(b[2] == 3);
109
	assert(b[2] == 3);
110
}
110
}
111
111
112
/* n > smax */
112
/* n > smax, handler */
113
ATF_TC_WITHOUT_HEAD(n_gt_smax);
113
ATF_TC_WITHOUT_HEAD(n_gt_smax);
114
ATF_TC_BODY(n_gt_smax, tc)
114
ATF_TC_BODY(n_gt_smax, tc)
115
{
115
{
116
	char b[3] = {1, 2, 3};
116
	char b[3] = {1, 2, 3};
117
117
118
	assert(memset_s(&b[0], 1, 9, 3) == 0);
118
	e = 0;
119
	m = NULL;
120
	set_constraint_handler_s(h);
121
	assert(memset_s(&b[0], 1, 9, 3) != 0);
122
	assert(e > 0);
123
	assert(strcmp(m, "memset_s : n > smax") == 0);
119
	assert(b[0] == 9);
124
	assert(b[0] == 9);
120
	assert(b[1] == 2);
125
	assert(b[1] == 2);
121
	assert(b[2] == 3);
126
	assert(b[2] == 3);

Return to bug 221323