2
0

Merge branch 'master' of gitlab.com:MasterPassword/MasterPassword

This commit is contained in:
Maarten Billemont
2018-06-25 13:22:36 -04:00
7 changed files with 90 additions and 36 deletions

View File

@@ -77,18 +77,28 @@ library {
static String standardOperatingSystem(NativePlatform platform) {
OperatingSystem os = platform.getOperatingSystem()
if (os.isWindows()) {
if (os.isWindows())
return OperatingSystemFamily.WINDOWS
} else if (os.isLinux()) {
return OperatingSystemFamily.LINUX
} else if (os.isMacOsX()) {
else if (os.isMacOsX())
return OperatingSystemFamily.MAC_OS
}
else if (os.isLinux())
return OperatingSystemFamily.LINUX
return os.name.toLowerCase()
// Other systems will need to use a Linux compatibility layer for now.
return OperatingSystemFamily.LINUX
}
static String standardArchitecture(NativePlatform platform) {
Architecture arch = platform.getArchitecture()
return arch.name.toLowerCase().replaceAll( "-", "_" )
if (arch.isArm())
return "arm"
else if (arch.name.toLowerCase( Locale.ROOT ).startsWith( "arm" ))
return "arm64"
else if (arch.isAmd64())
return "x86_64"
else if (arch.isI386())
return "x86"
// Other systems will need to be compatible with the x86 architecture.
return "x86"
}

View File

@@ -66,18 +66,20 @@ const char **mpw_strings(size_t *count, const char *strings, ...) {
va_list args;
va_start( args, strings );
char **array = NULL;
size_t arraySize = 0;
for (const char *string; string = va_arg( args, const char * );) {
size_t cursor = arraySize;
if (!mpw_realloc( &array, &arraySize, sizeof(string) )) {
mpw_free( &array, arraySize );
const char **array = NULL;
size_t size = 0;
for (const char *string = strings; string; (string = va_arg( args, const char * ))) {
size_t cursor = size / sizeof( *array );
if (!mpw_realloc( &array, &size, sizeof( string ) )) {
mpw_free( &array, size );
*count = 0;
return NULL;
}
array[cursor] = string;
}
va_end( args );
*count = size / sizeof( *array );
return array;
}
@@ -311,7 +313,7 @@ static uint8_t const *mpw_aes(bool encrypt, const uint8_t *key, const size_t key
AES_CBC_encrypt_buffer( resultBuf, aesBuf, aesSize, key, iv );
else
AES_CBC_decrypt_buffer( resultBuf, aesBuf, aesSize, key, iv );
mpw_free( aesBuf, aesSize );
mpw_free( &aesBuf, aesSize );
// Truncate PKCS#7 padding
if (encrypt)
@@ -516,14 +518,11 @@ char *mpw_strndup(const char *src, size_t max) {
return dst;
}
int *mpw_strncasecmp(const char *s1, const char *s2, size_t max) {
int mpw_strncasecmp(const char *s1, const char *s2, size_t max) {
if (s1 && s2 && max)
for (; --max > 0; ++s1, ++s2) {
int cmp = tolower( *(unsigned char *)s1 ) - tolower( *(unsigned char *)s2 );
if (!cmp || *s1 == '\0')
return cmp;
}
int cmp = 0;
for (; !cmp && max-- > 0 && s1 && s2; ++s1, ++s2)
cmp = tolower( *(unsigned char *)s1 ) - tolower( *(unsigned char *)s2 );
return 0;
}
return cmp;
}

View File

@@ -118,9 +118,9 @@ bool mpw_push_int(
/** Reallocate the given buffer from the given size by adding the delta size.
* On success, the buffer size pointer will be updated to the buffer's new size
* and the buffer pointer may be updated to a new memory address.
* On failure, the buffer and pointers will remain unaffected.
* On failure, the pointers will remain unaffected.
* @param buffer A pointer to the buffer to reallocate.
* @param bufferSize A pointer to the buffer's actual size.
* @param bufferSize A pointer to the buffer's current size.
* @param deltaSize The amount to increase the buffer's size by.
* @return true if successful, false if reallocation failed.
*/
@@ -216,6 +216,6 @@ char *mpw_strdup(const char *src);
/** Drop-in for POSIX strndup(3). */
char *mpw_strndup(const char *src, size_t max);
/** Drop-in for POSIX strncasecmp(3). */
int *mpw_strncasecmp(const char *s1, const char *s2, size_t max);
int mpw_strncasecmp(const char *s1, const char *s2, size_t max);
#endif // _MPW_UTIL_H