Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

function u2fh_register2 get wrong result because pointer error #89

Closed
AtlantisFox opened this issue Oct 20, 2017 · 5 comments
Closed

function u2fh_register2 get wrong result because pointer error #89

AtlantisFox opened this issue Oct 20, 2017 · 5 comments

Comments

@AtlantisFox
Copy link

I use function u2fh_register2 to test my token,but I get puzzling results
So I write simple test code to reappear the puzzling results
You may have noticed that the &p in str2 is defferent to main &p
Please fix it.Thank you

Test Code

#include <stdio.h>
#include <stdlib.h>

void test_addr(char **p) {
	printf("test_p = %p\n", p);
}

void str1(char **p) {
	printf("str1_**p = %p\n", p);
	test_addr(p);
}

void str2(char *p) {
	printf("str2_*p = %p\n", p);
	printf("str2_**p = %p\n", &p);
	test_addr(&p);
}

int main(int argc, char const *argv[])
{
	char *p = (char *)malloc(10 * sizeof(char));
	printf("mainp = %p main&p = %p\n",p, &p);
	str1(&p);
	str2(p);
	free(p);
	return 0;
}

Result

mainp = 00BA13A8 main&p = 0060FF2C
str1_**p = 0060FF2C
test_p = 0060FF2C
str2_*p = 00BA13A8
str2_**p = 0060FF10
test_p = 0060FF10

@klali
Copy link
Member

klali commented Oct 25, 2017

In what way does this impact the u2fh_register2() function and what errors does it lead to?
And do you have a proposed way of fixing this?

@AtlantisFox
Copy link
Author

error

please note the response in u2fh_register2().the response is same as p in my test code.if you use the u2fh_register2(),you may get wrong result in response,because function u2fh_register2() write to wrong address

in test code result,you can see that if we use str2,it write result in 0x0060FF10 rather then 0x0060FF2C

U2FH_EXPORT u2fh_rc u2fh_register (u2fh_devs * devs,
				const char *challenge,
				const char *origin,
				char **response, u2fh_cmdflags flags);

U2FH_EXPORT u2fh_rc u2fh_register2 (u2fh_devs * devs,
				 const char *challenge,
				 const char *origin,
				 char *response, size_t * response_len,
				 u2fh_cmdflags flags);
u2fh_rc
u2fh_register2 (u2fh_devs * devs,
		const char *challenge,
		const char *origin, char *response, size_t * response_len,
		u2fh_cmdflags flags)
{
  return _u2fh_register (devs, challenge, origin, &response, response_len,
			 flags);
}
u2fh_rc
u2fh_register (u2fh_devs * devs,
	       const char *challenge,
	       const char *origin, char **response, u2fh_cmdflags flags)
{
  size_t response_len = 0;
  *response = NULL;
  return _u2fh_register (devs, challenge, origin, response, &response_len,
			 flags);
}

solution

you can change u2fh_register2 response from char * to char **,and fix _u2fh_register
the u2fh_authenticate2 can be fixed use the same method

U2FH_EXPORT u2fh_rc u2fh_register2 (u2fh_devs * devs,
				 const char *challenge,
				 const char *origin,
				 char **response, size_t * response_len,
				 u2fh_cmdflags flags);
u2fh_rc
u2fh_register2 (u2fh_devs * devs,
		const char *challenge,
		const char *origin, char **response, size_t * response_len,
		u2fh_cmdflags flags)
{
  return _u2fh_register (devs, challenge, origin, response, response_len,
			 flags);

@klali
Copy link
Member

klali commented Oct 27, 2017

We never write to the response directly, only to the dereferenced version of it.
Can you show an example that breaks the way it is now?
Changing the API is not really an option.

@AtlantisFox
Copy link
Author

In function u2fh_register2, the parameter sent to _u2fh_register is &response, which is different from that of u2f_register. That would cause a problem as I stated in the first example.

@nevun
Copy link
Contributor

nevun commented Oct 14, 2020

We are archiving this project and closing issues. Please open a new one in the replacement library's repo: https://github.com/Yubico/libfido2 if it is still applicable.

@nevun nevun closed this as completed Oct 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants