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

小米 MIX4 MIUI13 bug #3316

Closed
AReverso opened this issue Feb 3, 2022 · 22 comments
Closed

小米 MIX4 MIUI13 bug #3316

AReverso opened this issue Feb 3, 2022 · 22 comments
Labels
solution: invalid the issue is not related to the library

Comments

@AReverso
Copy link

AReverso commented Feb 3, 2022

The screenshot of the interception in this mobile phone C is garbled as follows. My miui12 interception is normal. Can I reply to it?
image

@nlohmann
Copy link
Owner

nlohmann commented Feb 3, 2022

The exception message states the issue: you have an unescaped null byte in your input. This is invalid JSON - null bytes must be escaped to \u0000. The exception also states the position of the null byte its after 59884.

This is not a bug in the library.

@nlohmann nlohmann removed the kind: bug label Feb 3, 2022
@AReverso
Copy link
Author

AReverso commented Feb 3, 2022

异常消息说明了问题:您的输入中有一个未转义的空字节。这是无效的 JSON - 必须将空字节转义为\u0000. 该异常还说明了空字节在其之后的位置59884

这不是库中的错误。

using json = nlohmann::ordered_json;
char json_msg[4096] = "";
json result = json::parse(user_data);
sprintf(json_msg, "%s", result["msg"].get < std::string > ().c_str());

int json_code_int = result["code"].get < int >();
printf("code:%s,%d\n", json_msg, json_code_int);

This is my code, how to solve the problem you mentioned? I want to get code and msg! thanks

@nlohmann
Copy link
Owner

nlohmann commented Feb 3, 2022

I assume line

json result = json::parse(user_data);

throws the exception, right?

@AReverso
Copy link
Author

AReverso commented Feb 4, 2022

using json = nlohmann::ordered_json;
char json_msg[4096] = "";
char mem[4096] = "";
int json_code_int;
int json_time_int;
 try
{

	json result = json::parse(user_data);
	sprintf(json_msg, "%s", result["msg"].get < std::string > ().c_str());
 json_code_int = result["code"].get < int >();
    json_time_int = result["time"].get < int >();
    printf("msg:%s\ncode:%d\ntime:%d\n\n", json_msg, json_code_int,json_time_int);

} catch(json::exception & e)
{

	sprintf(mem, "%s", e);
	printf("mistake:%s\n\n", mem);

}

This is my code.

There is no problem with Xiaomi 9 input!

NPA%@3AYHSM_S33YN9E5REG

Xiaomi 4mix miui13 output is like this.

image

@AReverso
Copy link
Author

AReverso commented Feb 4, 2022

I assume line

json result = json::parse(user_data);

throws the exception, right?

Look at my new reply above and see what the problem is. Thank you.

@nlohmann
Copy link
Owner

nlohmann commented Feb 4, 2022

If you enter the catch branch, can you please output the content of e.what() to check which exception occurred?

@AReverso
Copy link
Author

AReverso commented Feb 4, 2022

If you enter the catch branch, can you please output the content of e.what() to check which exception occurred?

using json = nlohmann::ordered_json;
char json_msg[4096] = "";
char mem[4096] = "";
int json_code_int;
int json_time_int;
 try
{

	json result = json::parse(user_data);
	sprintf(json_msg, "%s", result["msg"].get < std::string > ().c_str());
 json_code_int = result["code"].get < int >();
    json_time_int = result["time"].get < int >();
    printf("msg:%s\ncode:%d\ntime:%d\n\n", json_msg, json_code_int,json_time_int);

} catch(json::exception & e)
{

	sprintf(mem, "%s", e);
	printf("mistake:%s\n\n", mem);

}

This is the e I printed, and the error output is empty. Look at my circle. Is there something wrong with my printing error code?

Uploading 23e95b62a5eda287.jpg…

@nlohmann
Copy link
Owner

nlohmann commented Feb 4, 2022

Please use

std::cout << "exception: " << e.what() << std::endl;

@AReverso
Copy link
Author

AReverso commented Feb 4, 2022

Please use

std::cout << "exception: " << e.what() << std::endl;

Is it because the msg length is too long? How to solve this mistake?

image

@nlohmann
Copy link
Owner

nlohmann commented Feb 4, 2022

The error is the same. There is an unescaped null byte in your input, and the parser rightfully complains that this is invalid JSON. What type does user_data have?

@AReverso
Copy link
Author

AReverso commented Feb 4, 2022

The error is the same. There is an unescaped null byte in your input, and the parser rightfully complains that this is invalid JSON. What type does user_data have?

const char *user_data = User_login(secret_key, app, appkey, Urlry, kmm, kmm_m, jqm);
printf("\nuser_data:%s\n\n", user_data);

This is the code of my user_data. I have no problem with my phone, my friend's phone has a problem, so I don't know what to do

@nlohmann
Copy link
Owner

nlohmann commented Feb 4, 2022

Please double check that there is a null byte in the input of the parser. Can you print the output of std::strlen(user_data)?

@AReverso
Copy link
Author

AReverso commented Feb 4, 2022

Please double check that there is a null byte in the input of the parser. Can you print the output of std::strlen(user_data)?

The above print is user_data, len is 765, you just asked me to print it, the json content must be there, but I don't know why the parsing error

image

@AReverso

This comment was marked as duplicate.

@nlohmann
Copy link
Owner

nlohmann commented Feb 4, 2022

That's really strange. Can you please try to copy user_data to a std::string and call the parser with that string?

std::string tmp = user_data;
std::cout << "strlen: " << std::strlen(user_data) << " - size(): " << tmp.size() << std::endl;
json result = json::parse(tmp);

@AReverso
Copy link
Author

AReverso commented Feb 4, 2022

That's really strange. Can you please try to copy user_data to a std::string and call the parser with that string?

std::string tmp = user_data;
std::cout << "strlen: " << std::strlen(user_data) << " - size(): " << tmp.size() << std::endl;
json result = json::parse(tmp);
const char *user_data = User_login(secret_key, app, appkey, Urlry, kmm, kmm_m, jqm);
printf("\nuser_data:%s\n\n", user_data);
 

std::string tmp = user_data;
std::cout << "strlen: " << std::strlen(user_data) << " - size(): " << tmp.size() << std::endl;


using json = nlohmann::ordered_json;
char json_msg[4096] = "";
char mem[4096] = "";
int json_code_int;
int json_time_int;
 try
{

	json result = json::parse(tmp);
	sprintf(json_msg, "%s", result["msg"].get < std::string > ().c_str());
 json_code_int = result["code"].get < int >();
    json_time_int = result["time"].get < int >();
   printf("msg:%s\ncode:%d\ntime:%d\n\n", json_msg, json_code_int,json_time_int);

} catch(json::exception & e)
{


	std::cout << "exception: " << e.what() << std::endl;

}

image

@nlohmann
Copy link
Owner

nlohmann commented Feb 4, 2022

The strlen of 0 looks bad, and the error message as well.

Can you please run your code with address sanitizer or Valgrind? There seem to be some memory problem.

@AReverso
Copy link
Author

AReverso commented Feb 4, 2022

The strlen of 0 looks bad, and the error message as well.

Can you please run your code with address sanitizer or Valgrind? There seem to be some memory problem.

If the length is very short, my friend's mobile phone can intercept normally

image

@gregmarr
Copy link
Contributor

gregmarr commented Feb 4, 2022

My guess at this point is that User_login is returning a pointer to internal temporary storage that is then being overwritten in another thread. That's the only way I can see to have strlen(user_data) be 0 after copying the contents to the std::string.

Is the User_login function under your control?

@AReverso
Copy link
Author

AReverso commented Feb 5, 2022

My guess at this point is that User_login is returning a pointer to internal temporary storage that is then being overwritten in another thread. That's the only way I can see to have strlen(user_data) be 0 after copying the contents to the std::string.

Is the User_login function under your control?

Thank you for your answers. I gave up json and directly intercepted the data. This way the compatibility is better. My friend's mobile phone and I have no problem. Thank you for your answers. Thank you

@AReverso
Copy link
Author

AReverso commented Feb 5, 2022

The strlen of 0 looks bad, and the error message as well.

Can you please run your code with address sanitizer or Valgrind? There seem to be some memory problem.

Thank you for your answers. I gave up json and directly intercepted the data. This way the compatibility is better. My friend's mobile phone and I have no problem. Thank you for your answers. Thank you

@AReverso
Copy link
Author

AReverso commented Feb 5, 2022

The strlen of 0 looks bad, and the error message as well.
Can you please run your code with address sanitizer or Valgrind? There seem to be some memory problem.

Thank you for your answers. I gave up json and directly intercepted the data. This way the compatibility is better. My friend's mobile phone and I have no problem. Thank you for your answers. Thank you

If you can, you can delete this question, I solved it, thank you author

@nlohmann nlohmann added the solution: invalid the issue is not related to the library label Feb 5, 2022
@nlohmann nlohmann closed this as completed Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

3 participants