Memcpy Crash Only on iPhone 5s

All,

I am having a strange problem with iPhone 5s. I use encryption HMAC-SHA1in my application using a third-party library. The library is used memcpy, which does not know what it is, since I do not deal with too much memory level programming in C. Encryption works fine in all iphones except 64 bit 5s. Below is the code in which it crashes (5th line).

void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len)
{
unsigned int i, j;

    j = (context->count[0] >> 3) & 63;
    if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
    context->count[1] += (len >> 29);
    if ((j + len) > 63) {
        memcpy(&context->buffer[j], data, (i = 64-j));
        SHA1Transform(context->state, context->buffer);
        for ( ; i + 63 < len; i += 64) {
            SHA1Transform(context->state, &data[i]);
        }
        j = 0;
    }
    else i = 0;
    memcpy(&context->buffer[j], &data[i], len - i);
}

Below are the crash details

Type of exception: EXC_BAD_ACCESS (SIGSEGV) Subtype of exception: KERN_INVALID_ADDRESS at 0x001a9c799cbfdcf9 Related trigger: 0

0 : 0 libsystem_platform.dylib 0x0000000191c34dc8 _platform_memmove + 40 1 Anyvan 0x00000001001fc6a8 SHA1Update (sha1.c: 128) 2 Anyvan 0x00000001000c7efc hmac_sha1 (hmac.c: 73) 3 Anyvan 0x00000001000fe7cc - [LoginViewController callAuth:] (LoginViewController.m: 360)

.

+1
4

, int - memcpy. int NSInteger, . .

iPhone5S 64- , 32-. , , . unsigned int, 32- 64- , . int int j NSIntegers, , . , int long.

+3

Twitter + OAuth 64- . , "unsigned long" "uint32_t" 7 sha1.h sha1.c. :

#include <stdint.h>
typedef struct {
    uint32_t state[5];
    uint32_t count[2];
    unsigned char buffer[64];
} SHA1_CTX;

stdint.h( sha1.h , , sha1.c), . uint32_t 32 , , SHA1, R0, 64- . , 32- . memcpy .

+2

arm64, . NO "Build Active Architecture Only" ( )

, - 64- , .

-1

void CSHA1:: ( UINT_8 *, ) {}

I just changed the lent form of UINT_32 to a long one and it really worked, now you can work on 4, 5, 5, 6 hah

-1
source

Source: https://habr.com/ru/post/1541379/


All Articles