-
Notifications
You must be signed in to change notification settings - Fork 33
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
Fix Teeworlds server query, #3 #4
Conversation
@@ -511,3 +511,4 @@ gametype ALIENARENAM new extend Q2M | |||
master query = empty full | |||
master for gametype = ALIENARENAS | |||
end | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
irelavent change, please remove from the commit.
Overall can you please update the formatting for the teeworld module as per the new style, which is based off: An example of this can be found in the dirty bomb module. |
That was because
Because the
OK. Good idea.
Yes, unfortunately, I see that pointless thing after my pull request so I did not rewrite the commit to not pollute the git history and the github history (because the commit name contains the issue number, each commit rewrite can appear in the issue #3 thread). I've already deleted this useless line, so it will disappear in my next commit (master server). I will propose a clean pull request with server support fix + new master server when master support will be finished. The master server support is well underway, but I need a little help, cf. #5 😉 |
You can delete the line and commit --amend to update your pull request. |
19d978a
to
d6a96f9
Compare
I rewritten the commit. |
} | ||
|
||
/* version */ | ||
version = strdup (rawpkt); rawpkt += strlen (rawpkt) + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each line should be on a separate new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with that, I have done that for only one reason: mimic the existing code because it is a prudent way to do what others expect.
7993762
to
ebe44a6
Compare
|
||
server->protocol_version = 0; | ||
|
||
if (NULL == (tok = strtok(version, "."))) return -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returns should be on a new line and NULL at the other side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, also, -1
has a name, SYS_ERROR
.
My big question is "how this code was accepted before?" 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should return PKT_ERROR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is worse than I imagined. 😆
Thanks for fixing the issues, appreciate half of them are legacy code, but best to fix them as your going through :) |
This pull request is for #3 |
Hi, what do you think about renaming |
I'd keep that change separate if we did it.
|
OK, can you confirme it is safe to free this |
Hi, we are close to do it. I think the only one thing that prevent you to merge now is my question above, if you say yes, I will modify these lines and you will be able to merge after that. |
Hi, I've updated. The part with the useless |
Your strnlen tests where fine but add_rule uses strdup so if its not null terminated then "boom" ;-) |
} | ||
|
||
/* not null-terminated packet */ | ||
if (strnlen(rawpkt, rawpktlen) == rawpktlen && rawpkt[rawpktlen - 1] != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the strlen, surely that will always fail as the last byte is expected to be 0 hence the length with be rawpktlen - 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to test "there is no null before end" (length=maxlength) and "last is not null"
Just to verify:
$ cat a.c
#include <stdio.h>
#include <strings.h>
int main (void) {
char tab1[3]={'a', 'b', 'c'};
char tab2[3]={'a', 'b', 0};
printf("not terminated: %d\n", strnlen(tab1, 3));
printf("null terminated: %d\n", strnlen(tab2, 3));
}
$ gcc -o a a.c
$ ./a
not terminated: 3
null terminated: 2
So, strnlen
returns rawpktlen
if not terminated string, first condition works and is sufficient, no need to test the last character.
So only:
if (strnlen(rawpkt, rawpktlen) == rawpktlen) {
return (PKT_ERROR);
}
is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you still need the null check as strnlen will return rawpktlen even if it wasn't null terminated.
Any update on this @illwieckz ? |
Hi @stevenh, I do not forget this, it's just that I do not have much time these days. I'll work on it soon. 😉 |
No problem just checking :) |
Just to say, I will probably be able to work on it in july or august. I’m not forgetting this, I’m just very busy. :-) |
/* if inf2 or inf3 */ | ||
if (last_char == '2' || last_char == '3') { | ||
/* token, skip */ | ||
current += strnlen(current, end - current) + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you could simply these tests by switching to maintaining a "remaining" instead of having to constantly check against end - current?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't know why, but my question disappeared, I was asking if I can just do that:
current += strlen(current) + 1;
since I already checked that the packet is NULL-terminated.
This PR is nearly 1 year old. Outline any remaining issues in PR's description perhaps? |
Hi, this fixes the Teeworlds server query, it tries with the 3 known
getinfo
packets.I renamed the
-tee
argument to-tees
since I will work next on the-teem
Teeworlds master query.Since Teeworlds support was broken since many years, there is probably nobody that uses the
-tee
arg today.