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

Authentication Failure Content Incorrect #173

Open
rdnn opened this issue Aug 20, 2024 · 3 comments
Open

Authentication Failure Content Incorrect #173

rdnn opened this issue Aug 20, 2024 · 3 comments

Comments

@rdnn
Copy link

rdnn commented Aug 20, 2024

response.setContent(authStr.c_str());

I believe this should be:

response.setContent(authFailMsg);
@mathieucarbou
Copy link
Collaborator

mathieucarbou commented Aug 20, 2024

The code is right, the bug is elsewhere.

Response object has:

const char * _body;

Instead of:

String _body

So when the caller method exits, authStr is deallocated and the pointer to its underlying char array does not exist anymore. Sadly this is what the response object still points to

I saw similar dereferencing issues in the v2 branch we are working on.

Blindly fixing that using String might cause some heap memory issues.

Ideally we should stream directly the body to the wire (or the IDF API) but I don't know if this is possible.

@hoeken : FYI

@rdnn
Copy link
Author

rdnn commented Aug 20, 2024

The code is right, the bug is elsewhere.

authFailMsg is never used in PsychicRequest::requestAuthentication(). The code, as is, uses authStr for the header and content, which I don't believe is the desired behavior.

@mathieucarbou
Copy link
Collaborator

The code is right, the bug is elsewhere.

authFailMsg is never used in PsychicRequest::requestAuthentication(). The code, as is, uses authStr for the header and content, which I don't believe is the desired behavior.

Oh sorry! Yes you are right for the usage. The description of the failure should be returned.
Though it requires the pointer to still be valid, plus, content type is fixed to htm.
This part of the code will be changed to a middleware in v2 which is more flexible and which can be applied to several endpoints.

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

2 participants