Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to access TEE_ObjectHandle attribute: dereferencing pointer to incomplete type 'struct __TEE_ObjectHandle' #2494

Closed
cezane opened this issue Aug 13, 2018 · 6 comments

Comments

@cezane
Copy link

cezane commented Aug 13, 2018

I would like to know why I can not just access some ObjectHandle attribute like in this code:

void prepare_rsa_operation(TEE_OperationHandle *handle, uint32_t alg, TEE_OperationMode mode, TEE_ObjectHandle key) {
    (....)
    ret = TEE_AllocateOperation(&handle, alg, mode, key->dataLen);

The key->dataLen part is returning the following error:

rsa_crypto.c:25:64: error: dereferencing pointer to incomplete type 'struct __TEE_ObjectHandle'
ret = TEE_AllocateOperation(&handle, alg, mode, (uint32_t) key->dataLen);
^~

Can anyone explain me why, please?
Thank you.

@lorc
Copy link
Contributor

lorc commented Aug 13, 2018

Hi @cezane,

You don't need to take address of handle. Try in this way:

ret = TEE_AllocateOperation(handle, alg, mode, key->dataLen);

@jforissier
Copy link
Contributor

TEE_ObjectHandle is an opaque type, which means the application cannot access its internal representation. A TEE_ObjectHandle value may only be manipulated using the API.

Perhaps what you're after is TEE_GetObjectInfo1(TEE_ObjectHandle object, TEE_ObjectInfo *objectInfo); then access objectInfo->dataSize?

@cezane
Copy link
Author

cezane commented Aug 13, 2018

Hi, @lorc . Can you explain me why your suggestion? For me, if I pass like you are suggesting (ret = TEE_AllocateOperation(handle, alg, mode, key->dataLen);), I will be passing handle by value; but, instead, I want it passed by reference, since I want the changes reflect outside that function also. Am I wrong with this thought?

@cezane
Copy link
Author

cezane commented Aug 13, 2018

Thank you by explanation, @jforissier . In this case, as you said, I have to use TEE_GetObjectInfo1 to do what I want.

@lorc
Copy link
Contributor

lorc commented Aug 13, 2018

Hi, @cezane,

I was partly mistaken. This is not related to your question, but looks like you have an another bug there.

If I got your code snippet right, you have a function

void prepare_rsa_operation(TEE_OperationHandle *handle, uint32_t alg, TEE_OperationMode mode, TEE_ObjectHandle key)

And inside this function you invoke TEE_AllocateOperation(TEE_OperationHandle *operation, uint32_t algorithm, uint32_t mode, uint32_t maxKeySize)

As you can see, first parameter is a pointer to TEE_OperationHandle. This is exactly what you receive in your prepare_rsa_operation() as a first parameter. But, you want to call TEE_AllocateOperation() with &handle. This will have a type TEE_OperationHandle ** and compiler must at least warn you there.

You are already passing pointer to TEE_OperationHandle in prepare_rsa_operation, you will see changes outside it. Pointers in C is not the same thing as references in C++ or Java. You can't create reference to reference in C++, but you can easily create a pointer to pointer to pointer in C. So I recommend you to compile your code with -Wall -Werror options, so compiler will stop you from using dubious constructions.

@cezane
Copy link
Author

cezane commented Aug 13, 2018

Yes. Sure, @lorc . You are right. Understood, now, what you said and my mistake, since I was already receiving a pointer in the function.

Thank you.

@cezane cezane closed this as completed Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants