diff options
Diffstat (limited to 'include/compat')
| -rw-r--r-- | include/compat/dirent_msvc.h | 13 | ||||
| -rw-r--r-- | include/compat/endian.h | 18 | ||||
| -rw-r--r-- | include/compat/pthread.h | 7 | ||||
| -rw-r--r-- | include/compat/stdio.h | 20 | ||||
| -rw-r--r-- | include/compat/sys/time.h | 11 | ||||
| -rw-r--r-- | include/compat/syslog.h | 20 | ||||
| -rw-r--r-- | include/compat/unistd.h | 5 |
7 files changed, 51 insertions, 43 deletions
diff --git a/include/compat/dirent_msvc.h b/include/compat/dirent_msvc.h index 67f295f..2689399 100644 --- a/include/compat/dirent_msvc.h +++ b/include/compat/dirent_msvc.h | |||
| @@ -47,6 +47,7 @@ | |||
| 47 | 47 | ||
| 48 | #include <stdarg.h> | 48 | #include <stdarg.h> |
| 49 | #include <sys/stat.h> | 49 | #include <sys/stat.h> |
| 50 | #include <stdint.h> | ||
| 50 | 51 | ||
| 51 | /* Indicates that d_type field is available in dirent structure */ | 52 | /* Indicates that d_type field is available in dirent structure */ |
| 52 | #define _DIRENT_HAVE_D_TYPE | 53 | #define _DIRENT_HAVE_D_TYPE |
| @@ -154,7 +155,7 @@ _wopendir(const wchar_t *dirname) | |||
| 154 | /* Allocate new _WDIR structure */ | 155 | /* Allocate new _WDIR structure */ |
| 155 | dirp =(_WDIR*) malloc(sizeof(struct _WDIR)); | 156 | dirp =(_WDIR*) malloc(sizeof(struct _WDIR)); |
| 156 | if (dirp != NULL) { | 157 | if (dirp != NULL) { |
| 157 | DWORD n; | 158 | DWORD n, len; |
| 158 | 159 | ||
| 159 | /* Reset _WDIR structure */ | 160 | /* Reset _WDIR structure */ |
| 160 | dirp->handle = INVALID_HANDLE_VALUE; | 161 | dirp->handle = INVALID_HANDLE_VALUE; |
| @@ -165,7 +166,8 @@ _wopendir(const wchar_t *dirname) | |||
| 165 | n = GetFullPathNameW(dirname, 0, NULL, NULL); | 166 | n = GetFullPathNameW(dirname, 0, NULL, NULL); |
| 166 | 167 | ||
| 167 | /* Allocate room for absolute directory name and search pattern */ | 168 | /* Allocate room for absolute directory name and search pattern */ |
| 168 | dirp->patt =(wchar_t*) malloc(sizeof(wchar_t) * n + 16); | 169 | if (n <= (SIZE_MAX - 16) / sizeof(wchar_t)) |
| 170 | dirp->patt =(wchar_t*) malloc(sizeof(wchar_t) * n + 16); | ||
| 169 | if (dirp->patt) { | 171 | if (dirp->patt) { |
| 170 | 172 | ||
| 171 | /* | 173 | /* |
| @@ -173,12 +175,12 @@ _wopendir(const wchar_t *dirname) | |||
| 173 | * allows rewinddir() to function correctly even when current | 175 | * allows rewinddir() to function correctly even when current |
| 174 | * working directory is changed between opendir() and rewinddir(). | 176 | * working directory is changed between opendir() and rewinddir(). |
| 175 | */ | 177 | */ |
| 176 | n = GetFullPathNameW(dirname, n, dirp->patt, NULL); | 178 | len = GetFullPathNameW(dirname, n, dirp->patt, NULL); |
| 177 | if (n > 0) { | 179 | if (len > 0 && len < n) { |
| 178 | wchar_t *p; | 180 | wchar_t *p; |
| 179 | 181 | ||
| 180 | /* Append search pattern \* to the directory name */ | 182 | /* Append search pattern \* to the directory name */ |
| 181 | p = dirp->patt + n; | 183 | p = dirp->patt + len; |
| 182 | if (dirp->patt < p) { | 184 | if (dirp->patt < p) { |
| 183 | switch(p[-1]) { | 185 | switch(p[-1]) { |
| 184 | case '\\': | 186 | case '\\': |
| @@ -214,6 +216,7 @@ _wopendir(const wchar_t *dirname) | |||
| 214 | 216 | ||
| 215 | } else { | 217 | } else { |
| 216 | /* Cannot allocate memory for search pattern */ | 218 | /* Cannot allocate memory for search pattern */ |
| 219 | _set_errno(ENOMEM); | ||
| 217 | error = 1; | 220 | error = 1; |
| 218 | } | 221 | } |
| 219 | 222 | ||
diff --git a/include/compat/endian.h b/include/compat/endian.h index 89c83fc..8022e0e 100644 --- a/include/compat/endian.h +++ b/include/compat/endian.h | |||
| @@ -182,15 +182,15 @@ static inline uint64_t htole64(uint64_t x) { | |||
| 182 | uint64_t u64; | 182 | uint64_t u64; |
| 183 | unsigned char bytes[8]; | 183 | unsigned char bytes[8]; |
| 184 | } val; | 184 | } val; |
| 185 | val.u64 = x; | 185 | val.bytes[0] = (unsigned char)x; |
| 186 | return ((uint64_t)val.bytes[0] << 56) | | 186 | val.bytes[1] = (unsigned char)(x >> 8); |
| 187 | ((uint64_t)val.bytes[1] << 48) | | 187 | val.bytes[2] = (unsigned char)(x >> 16); |
| 188 | ((uint64_t)val.bytes[2] << 40) | | 188 | val.bytes[3] = (unsigned char)(x >> 24); |
| 189 | ((uint64_t)val.bytes[3] << 32) | | 189 | val.bytes[4] = (unsigned char)(x >> 32); |
| 190 | ((uint64_t)val.bytes[4] << 24) | | 190 | val.bytes[5] = (unsigned char)(x >> 40); |
| 191 | ((uint64_t)val.bytes[5] << 16) | | 191 | val.bytes[6] = (unsigned char)(x >> 48); |
| 192 | ((uint64_t)val.bytes[6] << 8) | | 192 | val.bytes[7] = (unsigned char)(x >> 56); |
| 193 | (uint64_t)val.bytes[7]; | 193 | return val.u64; |
| 194 | #endif | 194 | #endif |
| 195 | } | 195 | } |
| 196 | 196 | ||
diff --git a/include/compat/pthread.h b/include/compat/pthread.h index 8211dda..7702dcd 100644 --- a/include/compat/pthread.h +++ b/include/compat/pthread.h | |||
| @@ -110,8 +110,11 @@ pthread_mutex_unlock(pthread_mutex_t *mutex) | |||
| 110 | static inline int | 110 | static inline int |
| 111 | pthread_mutex_destroy(pthread_mutex_t *mutex) | 111 | pthread_mutex_destroy(pthread_mutex_t *mutex) |
| 112 | { | 112 | { |
| 113 | DeleteCriticalSection(mutex->lock); | 113 | if (mutex->lock != NULL) { |
| 114 | free(mutex->lock); | 114 | DeleteCriticalSection(mutex->lock); |
| 115 | free(mutex->lock); | ||
| 116 | mutex->lock = NULL; | ||
| 117 | } | ||
| 115 | return 0; | 118 | return 0; |
| 116 | } | 119 | } |
| 117 | 120 | ||
diff --git a/include/compat/stdio.h b/include/compat/stdio.h index 2ccdeeb..d9b8725 100644 --- a/include/compat/stdio.h +++ b/include/compat/stdio.h | |||
| @@ -57,7 +57,25 @@ int posix_rename(const char *oldpath, const char *newpath); | |||
| 57 | #endif | 57 | #endif |
| 58 | 58 | ||
| 59 | #if defined(_MSC_VER) && _MSC_VER < 1900 | 59 | #if defined(_MSC_VER) && _MSC_VER < 1900 |
| 60 | #define snprintf _snprintf | 60 | #include <stdarg.h> |
| 61 | |||
| 62 | static inline int | ||
| 63 | libressl_snprintf(char *str, size_t size, const char *format, ...) | ||
| 64 | { | ||
| 65 | va_list ap; | ||
| 66 | int ret; | ||
| 67 | |||
| 68 | va_start(ap, format); | ||
| 69 | ret = _vsnprintf(str, size, format, ap); | ||
| 70 | va_end(ap); | ||
| 71 | |||
| 72 | /* _vsnprintf does not NUL-terminate when the output is truncated. */ | ||
| 73 | if (size != 0) | ||
| 74 | str[size - 1] = '\0'; | ||
| 75 | |||
| 76 | return ret; | ||
| 77 | } | ||
| 78 | #define snprintf libressl_snprintf | ||
| 61 | #endif | 79 | #endif |
| 62 | 80 | ||
| 63 | #endif | 81 | #endif |
diff --git a/include/compat/sys/time.h b/include/compat/sys/time.h index 2448969..0388333 100644 --- a/include/compat/sys/time.h +++ b/include/compat/sys/time.h | |||
| @@ -7,16 +7,15 @@ | |||
| 7 | #define LIBCRYPTOCOMPAT_SYS_TIME_H | 7 | #define LIBCRYPTOCOMPAT_SYS_TIME_H |
| 8 | 8 | ||
| 9 | #ifdef _MSC_VER | 9 | #ifdef _MSC_VER |
| 10 | /* | ||
| 11 | * Use the winsock struct timeval: it is what <openssl/dtls1.h> gives | ||
| 12 | * callers of DTLSv1_get_timeout() and the dgram BIO ctrls, so libssl | ||
| 13 | * must be built against the same layout. | ||
| 14 | */ | ||
| 10 | #include <winsock2.h> | 15 | #include <winsock2.h> |
| 11 | 16 | ||
| 12 | #define timeval libressl_timeval | ||
| 13 | #define gettimeofday libressl_gettimeofday | 17 | #define gettimeofday libressl_gettimeofday |
| 14 | 18 | ||
| 15 | struct timeval { | ||
| 16 | long long tv_sec; | ||
| 17 | long tv_usec; | ||
| 18 | }; | ||
| 19 | |||
| 20 | int gettimeofday(struct timeval *tp, void *tzp); | 19 | int gettimeofday(struct timeval *tp, void *tzp); |
| 21 | #else | 20 | #else |
| 22 | #include_next <sys/time.h> | 21 | #include_next <sys/time.h> |
diff --git a/include/compat/syslog.h b/include/compat/syslog.h index 3528eb3..c7a2608 100644 --- a/include/compat/syslog.h +++ b/include/compat/syslog.h | |||
| @@ -36,23 +36,3 @@ void vsyslog_r(int, struct syslog_data *, const char *, va_list); | |||
| 36 | #endif | 36 | #endif |
| 37 | 37 | ||
| 38 | #endif | 38 | #endif |
| 39 | |||
| 40 | #ifdef _AIX | ||
| 41 | #ifdef HAVE_SYSLOG | ||
| 42 | #include <stdlib.h> | ||
| 43 | void vsyslog(int facility_priority, const char *format, va_list arglist) { | ||
| 44 | char *msg = NULL; | ||
| 45 | vasprintf(&msg, format, arglist); | ||
| 46 | |||
| 47 | if (!msg) | ||
| 48 | return; | ||
| 49 | |||
| 50 | syslog(facility_priority, "%s", msg); | ||
| 51 | free(msg); | ||
| 52 | } | ||
| 53 | #endif /* HAVE_SYSLOG */ | ||
| 54 | |||
| 55 | void vsyslog_r(int pri, struct syslog_data *data, const char *fmt, va_list ap) { | ||
| 56 | vsyslog(pri, fmt, ap); | ||
| 57 | } | ||
| 58 | #endif /* AIX */ | ||
diff --git a/include/compat/unistd.h b/include/compat/unistd.h index 544cb27..0ce66dd 100644 --- a/include/compat/unistd.h +++ b/include/compat/unistd.h | |||
| @@ -75,8 +75,13 @@ int getentropy(void *buf, size_t buflen); | |||
| 75 | int getpagesize(void); | 75 | int getpagesize(void); |
| 76 | #endif | 76 | #endif |
| 77 | 77 | ||
| 78 | #ifndef HAVE_PLEDGE | ||
| 78 | #define pledge(request, paths) 0 | 79 | #define pledge(request, paths) 0 |
| 80 | #endif | ||
| 81 | |||
| 82 | #ifndef HAVE_UNVEIL | ||
| 79 | #define unveil(path, permissions) 0 | 83 | #define unveil(path, permissions) 0 |
| 84 | #endif | ||
| 80 | 85 | ||
| 81 | #ifndef HAVE_PIPE2 | 86 | #ifndef HAVE_PIPE2 |
| 82 | int pipe2(int fildes[2], int flags); | 87 | int pipe2(int fildes[2], int flags); |
