FreeBSD Bugzilla – Attachment 185140 Details for
Bug 221323
memset_s() and abort_handler_s() missed some standard notes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch to correct the mentioned issues, updating the memset_s test case as well
memset_s.diff (text/plain), 2.38 KB, created by
Yuri Pankov
on 2017-08-08 00:24:44 UTC
(
hide
)
Description:
patch to correct the mentioned issues, updating the memset_s test case as well
Filename:
MIME Type:
Creator:
Yuri Pankov
Created:
2017-08-08 00:24:44 UTC
Size:
2.38 KB
patch
obsolete
>diff --git a/lib/libc/stdlib/set_constraint_handler_s.c b/lib/libc/stdlib/set_constraint_handler_s.c >index dafdb16528b..5e13f0f9788 100644 >--- a/lib/libc/stdlib/set_constraint_handler_s.c >+++ b/lib/libc/stdlib/set_constraint_handler_s.c >@@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); > #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 @@ __throw_constraint_handler_s(const char * restrict msg, errno_t error) > } > > 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(); > } > >diff --git a/lib/libc/string/memset_s.c b/lib/libc/string/memset_s.c >index 9bb8e1cd5b9..859c8f130a5 100644 >--- a/lib/libc/string/memset_s.c >+++ b/lib/libc/string/memset_s.c >@@ -42,22 +42,25 @@ memset_s(void *s, rsize_t smax, int c, rsize_t n) > 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); > } >diff --git a/lib/libc/tests/string/memset_s_test.c b/lib/libc/tests/string/memset_s_test.c >index a8426eb3c78..e0cfd867ff2 100644 >--- a/lib/libc/tests/string/memset_s_test.c >+++ b/lib/libc/tests/string/memset_s_test.c >@@ -109,13 +109,18 @@ ATF_TC_BODY(n_lt_smax, tc) > 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);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 221323
: 185140