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

chan_tlb.c: finddelim update limit to length of strp from str #476

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

Conversation

mkmer
Copy link
Collaborator

@mkmer mkmer commented Jan 30, 2025

Check the correct length to prevent over running the output pointer.

@mkmer mkmer added the code quality Improvments around code quality without functional changes label Jan 30, 2025
@mkmer mkmer force-pushed the TLB-Channel branch 3 times, most recently from c47c93f to f5f5f3d Compare January 30, 2025 12:43
@@ -519,6 +519,9 @@ static int finddelim(char *str, char *strp[], int limit)
l++;
strp[i++] = str + 1;
}
if (i => limit) {
break;
}
}
strp[i] = 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure this makes sense to 0 the last pointer value in the array of pointers.
i => limit at least makes sure we are not writing outside of the limit

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree. It's OK to fill the last slot of the array ... as long as the call sites are iterating with for (i = 0; i < n; i++) {}. But, we would need the last element to be NULL if the usage is while (*ptr) {}. Regardless, if we have an array of size 10 we don't want to write to array[10].

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah - I see my problem. 0 based counts 0 - 9 = length of 10...

@mkmer mkmer force-pushed the TLB-Channel branch 3 times, most recently from 0ba8e05 to fda2659 Compare January 30, 2025 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Improvments around code quality without functional changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants