Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <YlTQgBwQEgukb3N3@ws>
Date: Tue, 12 Apr 2022 03:06:08 +0200
From: Wolf <wolf@...fsden.cz>
To: musl@...ts.openwall.com
Subject: Problem with strdupa in C++ code

Hello,

I'm trying to compile C++ project in Alpine (so with musl) and I'm
hitting following error:

    In file included from /usr/include/fortify/string.h:22,
                     from src/main/tools/linux-sandbox-pid1.cc:34:
    src/main/tools/linux-sandbox-pid1.cc: In function 'int CreateTarget(const char*, bool)':
    src/main/tools/linux-sandbox-pid1.cc:149:28: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
      149 |   if (CreateTarget(dirname(strdupa(path)), true) < 0) {
          |                            ^
          |                            |
          |                            void*
    In file included from /usr/include/fortify/string.h:22,
                     from src/main/tools/linux-sandbox-pid1.cc:34:
    /usr/include/string.h:31:15: note:   initializing argument 1 of 'char* strcpy(char*, const char*)'
       31 | char *strcpy (char *__restrict, const char *__restrict);
          |               ^~~~~~~~~~~~~~~~
    
If my reading for musl's code is correct, this is actually a bug in the
header file, since the declarations are:

    void *alloca(size_t);
    #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)

As far as I know, there is no automatic conversion from void* to char*
in C++. Should this be fixed by turning the define into

    #define	strdupa(x)	strcpy((char*)alloca(strlen(x)+1),x)

? I think that should be both valid C and C++.

Best regards,
Tomas Volf

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.