[botan-devel] Building in OSX 10.10

Justin Ferguson jf at ownco.net
Mon Jan 26 15:43:40 EST 2015


What a bizarre function. My first thought was "why does it take two length
parameters? One of these values should always be 1 or at the very least at
the maximum sizeof(character).

The proposal for the function is here:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1381.pdf

Basically it's secure in that it can't be optimized out or at least isn't
supposed to be.

You can probably fix it's absence by mucking around in autoconf and
essentially creating a #ifndef HAVE_MEMSET_S

errno_t
memset_s(void restrict* s, rsize_t smax, signed int c, size_t n)
{
        volatile unsigned char *p = s;

        if (NULL == dst || c  < n || RSIZE_MAX  < c || RSIZE_MAX  < n)
                return -EINVAL;

        while (n--)
                *p++ = c;

        return 0;
}

#endif

I've not actually tested that so things like RSIZE_MAX may require the
inclusion of a header and similar, but that's the basic idea.

And yes, that's not a mistake, with memset_s() the *second* length
parameter is the length of the destination buffer not the first, which
seems superfluous.

Further, it's important to check the return value of memset_s in any usage
where the destination pointer can be null, rsize can be greater than n or
either is larger than RSIZE_MAX because then the magic memset won't be
optimized out by the compiler but the runtime constraints will effectively
mean the programmer optimized it out and the data is not overwritten.

Justin
On Jan 26, 2015 11:47 AM, "Dennis Weldy" <dennis at correlatedmagnetics.com>
wrote:

>  It’s evidently supported in XCode tools 5.0
>
>
>
> Dennis
>
>
>
> *From:* botan-devel [mailto:botan-devel-bounces at randombit.net] *On Behalf
> Of *Stijn Frishert
> *Sent:* Monday, January 26, 2015 7:28 AM
> *To:* botan-devel at randombit.net
> *Subject:* [botan-devel] Building in OSX 10.10
>
>
>
> Hi everyone,
>
>
>
> I'm trying to build Botan 1.11.13 on OSX 10.10, but came across the same
> memset_s error reported by Uri Blumenthal on the 12th of January. Has this
> been fixed/a workaround been found yet?
>
>
>
> I would love to get started with Botan, but this compilation error keeps
> me from continuing.
>
>
>
> For completeness sake, the error once again:
>
>
>
> ------------
>
> stijn:Botan-1.11.13 stijn$ make
>
>
>
> g++ -m64 -pthread -fstack-protector -fPIC -fvisibility=hidden -std=c++11
> -D_REENTRANT -O2 -momit-leaf-frame-pointer -Wall -Wextra -Wstrict-aliasing
> -Wstrict-overflow=5 -Wcast-align -Wmissing-declarations -Wpointer-arith
> -Wcast-qual -Wold-style-cast -Wzero-as-null-pointer-constant
> -Ibuild/include -c src/lib/utils/zero_mem.cpp -o
> build/obj/lib/utils_zero_mem.o
>
> warning: unknown warning option '-Wzero-as-null-pointer-constant'; did you
> mean '-Wint-to-void-pointer-cast'?
>
>       [-Wunknown-warning-option]
>
> src/lib/utils/zero_mem.cpp:24:6: error: no member named 'memset_s' in the
> global namespace; did you mean
>
>       'memset'?
>
>    ::memset_s(ptr, n, 0, n);
>
>    ~~^~~~~~~~
>
>      memset
>
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/string.h:74:7:
> note:
>
>       'memset' declared here
>
> void    *memset(void *, int, size_t);
>
>          ^
>
> src/lib/utils/zero_mem.cpp:24:26: error: too many arguments to function
> call, expected 3, have 4
>
>    ::memset_s(ptr, n, 0, n);
>
>    ~~~~~~~~~~            ^
>
> 1 warning and 2 errors generated.
>
> make: *** [build/obj/lib/utils_zero_mem.o] Error 1
>
> ------------
>
> Kind regards,
>
>
>
> Stijn Frishert
>
> _______________________________________________
> botan-devel mailing list
> botan-devel at randombit.net
> http://lists.randombit.net/mailman/listinfo/botan-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.randombit.net/pipermail/botan-devel/attachments/20150126/68d9128e/attachment.html>


More information about the botan-devel mailing list