Page MenuHomeFreeBSD

D11991.1783800272.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D11991.1783800272.diff

Index: lib/libc/stdlib/set_constraint_handler_s.c
===================================================================
--- lib/libc/stdlib/set_constraint_handler_s.c
+++ lib/libc/stdlib/set_constraint_handler_s.c
@@ -32,6 +32,7 @@
#include <errno.h>
#include <pthread.h>
#include <stddef.h>
+#include <stdio.h>
#include <stdlib.h>
#include "un-namespace.h"
#include "libc_private.h"
@@ -81,10 +82,11 @@
}
void
-abort_handler_s(const char * restrict msg __unused,
- void * restrict ptr __unused, errno_t error __unused)
+abort_handler_s(const char * restrict msg, void * restrict ptr __unused,
+ errno_t error __unused)
{
+ (void) fprintf(stderr, "abort_handler_s : %s\n", msg);
abort();
}
Index: lib/libc/string/memset_s.c
===================================================================
--- lib/libc/string/memset_s.c
+++ lib/libc/string/memset_s.c
@@ -42,22 +42,25 @@
volatile unsigned char *dst;
ret = EINVAL;
- lim = smax;
+ lim = (n < smax) ? n : smax;
v = (unsigned char)c;
dst = (unsigned char *)s;
if (s == NULL) {
__throw_constraint_handler_s("memset_s : s is NULL", ret);
} else if (smax > RSIZE_MAX) {
__throw_constraint_handler_s("memset_s : smax > RSIZE_MAX",
- ret);
+ ret);
} else if (n > RSIZE_MAX) {
__throw_constraint_handler_s("memset_s : n > RSIZE_MAX", ret);
} else {
- if (n < smax)
- lim = n;
while (lim > 0)
dst[--lim] = v;
- ret = 0;
+ if (n > smax) {
+ __throw_constraint_handler_s("memset_s : n > smax",
+ ret);
+ } else {
+ ret = 0;
+ }
}
return (ret);
}
Index: lib/libc/tests/string/memset_s_test.c
===================================================================
--- lib/libc/tests/string/memset_s_test.c
+++ lib/libc/tests/string/memset_s_test.c
@@ -109,13 +109,18 @@
assert(b[2] == 3);
}
-/* n > smax */
+/* n > smax, handler */
ATF_TC_WITHOUT_HEAD(n_gt_smax);
ATF_TC_BODY(n_gt_smax, tc)
{
char b[3] = {1, 2, 3};
- assert(memset_s(&b[0], 1, 9, 3) == 0);
+ e = 0;
+ m = NULL;
+ set_constraint_handler_s(h);
+ assert(memset_s(&b[0], 1, 9, 3) != 0);
+ assert(e > 0);
+ assert(strcmp(m, "memset_s : n > smax") == 0);
assert(b[0] == 9);
assert(b[1] == 2);
assert(b[2] == 3);

File Metadata

Mime Type
text/plain
Expires
Sat, Jul 11, 8:04 PM (5 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29082889
Default Alt Text
D11991.1783800272.diff (2 KB)

Event Timeline