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

Replace use of strcpy by memcpy on String::concat(const char*,uint32_t) ? #590

Closed
bilaliscarioth opened this issue Jan 16, 2025 · 1 comment

Comments

@bilaliscarioth
Copy link

bilaliscarioth commented Jan 16, 2025

Hello Arduino Core Teams,

Can we replace the use of strcpy(2) from String::concat(const char*, uint32_t) by strlcpy(2) or even memcpy ?

Without referencing strcpy(2) on your documentation, if we cast a struct into char*, we could had
a null terminator between the start and the end, and strcpy(2) will never copy at the last char.

unsigned char String::concat(const char *cstr, unsigned int length)
{
	unsigned int newlen = len + length;
	if (!cstr) return 0;
	if (length == 0) return 1;
	if (!reserve(newlen)) return 0;
	strcpy(buffer + len, cstr);
	len = newlen;
	return 1;
}

Is it by choice, by using strcpy ?

Edit: The length is not taked care by strcpy, many edge case could resolve into BO

@bilaliscarioth bilaliscarioth changed the title Replace use of strcpy by strlcpy on String::concat(const char*,uint32_t) ? Replace use of strcpy by memcpy on String::concat(const char*,uint32_t) ? Jan 16, 2025
@bilaliscarioth
Copy link
Author

Duplicated of #530

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