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

don't rewrite .wpc file if session was not modified #375

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

feitoi
Copy link
Contributor

@feitoi feitoi commented Jul 18, 2023

To avoid rewriting the same .wpc file without having modified the session

@rofl0r
Copy link
Collaborator

rofl0r commented Jul 19, 2023

what's the problem with rewriting the session file?
as is, this commit is way too complex for my taste, and a lot of malloc/free going on which can lead to subtle bugs.

@feitoi
Copy link
Contributor Author

feitoi commented Jul 20, 2023

Main reason is to avoid unnecessary IO on the disk. Today many routers one day is easy to complete WPS transaction, but another day, I don't even know what is going on, WPS transaction fails, usually got timeout. Every 5 attempts, no matter if WPS transaction has completed or not, is called the save_session().

as is, this commit is way too complex for my taste, and a lot of malloc/free going on which can lead to subtle bugs.

Nothing complex. The build_session_sign() is called in the restore_session() and the save_session(). The restore_session() is called only at the beginning of the program and the save_session() is called every 5 attempts and end of the program. malloc/free is necessary for C 😅

@rofl0r
Copy link
Collaborator

rofl0r commented Jul 20, 2023

Nothing complex.

well, the commit adds 51 lines for something that can (maybe) be done in 3-6.
for example, how about checking return value for the function that tests a pin, and if it fails, do not advance wpc saving mechanism.

malloc/free is necessary for C 😅

not necessarily. there are other ways to manage memory, especially if it's of a fixed small size like here. i'd rather put a char[32] into the globule struct then allocating/freeing the entire time. for local use, a stack buffer (or in C lingua "automatic variable") is preferable.

@feitoi
Copy link
Contributor Author

feitoi commented Jul 21, 2023

And now, has it gotten better?

@rofl0r
Copy link
Collaborator

rofl0r commented Jul 22, 2023

yeah, a lot better, dont you think yourself ?

now if you could put the snprintf calls into a static void make_session_signature(char* out)
both calling sites can use the same code and there's no possibility to mess it up.

src/session.c Outdated
@@ -424,3 +439,9 @@ int jump_p2_queue(char* value)

return ret_val;
}

static void make_session_signature(char* out)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you put this before the first calling site, you dont need to declare it in session.h or anywhere else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified

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

Successfully merging this pull request may close these issues.

2 participants