Skip to content

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

Closed
@bilaliscarioth

Description

@bilaliscarioth

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions