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

Fix infinite loop in ns_turn_server.c #1460

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

Conversation

Asmir
Copy link

@Asmir Asmir commented Mar 24, 2024

In case ur_map_get returns 1 server will enter infinite loop because newid != 0.

@ggarber
Copy link
Contributor

ggarber commented Mar 31, 2024

Thank you for looking at this @Asmir . Good catch! Should we better refactor that code in this way?

do {
        if (TURN_RANDOM_SIZE == sizeof(mobile_id_t)) {
          newid = (mobile_id_t)turn_random();
        } else {
          newid = (mobile_id_t)turn_random();
          newid = (newid << 32) + (mobile_id_t)turn_random();
        }
        newid = newid & 0x00FFFFFFFFFFFFFFLL;
        if (!newid) {
           continue
        }
        newid = newid | sid;
    } while (ur_map_get(map, (ur_map_key_type)newid, NULL));

It looks to me like the current approach is overcomplicated and it is what led to this kind of bug that you found. What do you think?

@Asmir
Copy link
Author

Asmir commented Apr 3, 2024

This will not work because after if (!newId) check the continue statement will still cause ur_map_get to be called but with newid = 0, which is not what we want.

@ggarber
Copy link
Contributor

ggarber commented Apr 9, 2024

This will not work because after if (!newId) check the continue statement will still cause ur_map_get to be called but with newid = 0, which is not what we want.

ok, but can we fix that with:

} while (newid ==0 || ur_map_get(map, (ur_map_key_type)newid, NULL));

I think we need to fix the current double nested iteration

@Asmir
Copy link
Author

Asmir commented Apr 14, 2024

This will not work because after if (!newId) check the continue statement will still cause ur_map_get to be called but with newid = 0, which is not what we want.

ok, but can we fix that with:

} while (newid ==0 || ur_map_get(map, (ur_map_key_type)newid, NULL));

I think we need to fix the current double nested iteration

That would be a good solution.

@ggarber
Copy link
Contributor

ggarber commented Apr 19, 2024

This will not work because after if (!newId) check the continue statement will still cause ur_map_get to be called but with newid = 0, which is not what we want.

ok, but can we fix that with:

} while (newid ==0 || ur_map_get(map, (ur_map_key_type)newid, NULL));

I think we need to fix the current double nested iteration

That would be a good solution.

Can you apply it and do some basic testing if you can? Or you want me to do it? Thank you very much @Asmir

@Asmir
Copy link
Author

Asmir commented May 8, 2024

This will not work because after if (!newId) check the continue statement will still cause ur_map_get to be called but with newid = 0, which is not what we want.

ok, but can we fix that with:

} while (newid ==0 || ur_map_get(map, (ur_map_key_type)newid, NULL));

I think we need to fix the current double nested iteration

That would be a good solution.

Can you apply it and do some basic testing if you can? Or you want me to do it? Thank you very much @Asmir

If you don't mind applying the change since I moved to other projects and don't have my test environment.

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.

None yet

2 participants