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

Remove clever code #608

Closed
alejandro-colomar opened this issue Dec 16, 2022 · 2 comments
Closed

Remove clever code #608

alejandro-colomar opened this issue Dec 16, 2022 · 2 comments

Comments

@alejandro-colomar
Copy link
Collaborator

alejandro-colomar commented Dec 16, 2022

(void) snprintf (info_group.action+strlen (info_group.action),

If I I'm not missing something, this is a buffer overrun in the snprintf(3) call. I have plans to address it, which include defining this function for use in the entire project:

char *
shdw_stpeprintf(char *str, char *past_end, const char *restrict fmt, ...)
{
	int      len;
	char     *p;
	va_list  ap;

	if (str == past_end)
		return past_end;

	if (str == NULL)
		return NULL;

	va_start(ap, fmt);
	len = vsnprintf(str, past_end - str, fmt, ap);
	va_end(ap);

	if (len == -1)
		return NULL;

	if (len >= past_end - str)
		return past_end;

	return str + len;
}

This is a wrapper for snprintf(3) which allows easy chaining, and detecting truncation. Its design is very similar to stpecpy(3), which I designed here: https://software.codidact.com/posts/285946/287522#answer-287522

@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented Dec 16, 2022

Ahh, there's no overrun; there was a clever subtraction. Anyway, I still want to remove the cleverness, to avoid confusions and accidents.

@alejandro-colomar alejandro-colomar changed the title Buffer overrun in writing operation. Remove clever code Dec 16, 2022
@alejandro-colomar
Copy link
Collaborator Author

Fixed by #636

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

1 participant