Page MenuHomeFreeBSD

D11991.id31984.diff
No OneTemporary

D11991.id31984.diff

Index: head/lib/libc/stdlib/set_constraint_handler_s.c
===================================================================
--- head/lib/libc/stdlib/set_constraint_handler_s.c
+++ head/lib/libc/stdlib/set_constraint_handler_s.c
@@ -33,6 +33,8 @@
#include <pthread.h>
#include <stddef.h>
#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include "un-namespace.h"
#include "libc_private.h"
@@ -81,10 +83,14 @@
}
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)
{
+ static const char ahs[] = "abort_handler_s : ";
+ (void) _write(STDERR_FILENO, ahs, sizeof(ahs) - 1);
+ (void) _write(STDERR_FILENO, msg, strlen(msg));
+ (void) _write(STDERR_FILENO, "\n", 1);
abort();
}
Index: head/lib/libc/string/memset_s.c
===================================================================
--- head/lib/libc/string/memset_s.c
+++ head/lib/libc/string/memset_s.c
@@ -42,7 +42,7 @@
volatile unsigned char *dst;
ret = EINVAL;
- lim = smax;
+ lim = n < smax ? n : smax;
v = (unsigned char)c;
dst = (unsigned char *)s;
if (s == NULL) {
@@ -53,11 +53,14 @@
} 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: head/lib/libc/tests/string/memset_s_test.c
===================================================================
--- head/lib/libc/tests/string/memset_s_test.c
+++ head/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
Mon, Apr 6, 2:28 PM (19 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30976635
Default Alt Text
D11991.id31984.diff (2 KB)

Event Timeline