Skip to content

Commit 997950a

Browse files
peffgitster
authored andcommitted
imap-send: handle NO_OPENSSL even when openssl exists
If NO_OPENSSL is defined, then imap-send.c defines a fallback "SSL" type, which is just a void pointer that remains NULL. This works, but it has one problem: it is using the type name "SSL", which conflicts with the upstream name, if some other part of the system happens to include openssl. For example: $ make NO_OPENSSL=Nope OPENSSL_SHA1=Yes imap-send.o CC imap-send.o imap-send.c:35:15: error: conflicting types for ‘SSL’; have ‘void *’ 35 | typedef void *SSL; | ^~~ In file included from /usr/include/openssl/evp.h:26, from sha1/openssl.h:4, from hash.h:10, from object.h:4, from commit.h:4, from refs.h:4, from setup.h:4, from imap-send.c:32: /usr/include/openssl/types.h:187:23: note: previous declaration of ‘SSL’ with type ‘SSL’ {aka ‘struct ssl_st’} 187 | typedef struct ssl_st SSL; | ^~~ make: *** [Makefile:2761: imap-send.o] Error 1 This is not a terribly common combination in practice: 1. Why are we disabling openssl support but still using its sha1? The answer is that you may use the same build options across many versions, and some older versions of Git no longer build with modern versions of openssl. 2. Why are we using a totally unsafe sha1 that does not detect collisions? You're right, we shouldn't. But in preparation for using unsafe sha1 for non-cryptographic checksums, it would be nice to be able to turn it on without hassle. We can make this work by adjusting the way imap-send handles its fallback. One solution is something like this: #ifdef NO_OPENSSL #define git_SSL void * #else #define git_SSL SSL #endif But we can observe that we only need this definition in one spot: the struct which holds the variable. So rather than play around with macros that may cause unexpected effects, we can just directly use the correct type in that struct. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 39bf06a commit 997950a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

imap-send.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
#include "parse-options.h"
3030
#include "setup.h"
3131
#include "strbuf.h"
32-
#if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)
33-
typedef void *SSL;
34-
#endif
3532
#ifdef USE_CURL_FOR_IMAP_SEND
3633
#include "http.h"
3734
#endif
@@ -83,7 +80,11 @@ struct imap_server_conf {
8380

8481
struct imap_socket {
8582
int fd[2];
83+
#if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)
84+
void *ssl;
85+
#else
8686
SSL *ssl;
87+
#endif
8788
};
8889

8990
struct imap_buffer {

0 commit comments

Comments
 (0)