Re: [PATCH 4/4] kdb: Replace deprecated strcpy() with helper function in kdb_defcmd()
From: Doug Anderson
Date: Mon Aug 18 2025 - 16:44:46 EST
Hi,
On Mon, Aug 18, 2025 at 11:13 AM Thorsten Blum <thorsten.blum@xxxxxxxxx> wrote:
>
> +/*
> + * kdb_strdup_dequote - same as kdb_strdup(), but trims surrounding quotes from
> + * the input string if present.
> + * Remarks:
> + * Quotes are only removed if there is both a leading and a trailing quote.
> + */
> +char *kdb_strdup_dequote(const char *str, gfp_t type)
> +{
> + size_t len = strlen(str);
> + char *s;
> +
> + if (str[0] == '"' && len > 1 && str[len - 1] == '"') {
> + /* trim both leading and trailing quotes */
> + str++;
> + len -= 2;
> + }
> +
> + len++; /* add space for NUL terminator */
> +
> + s = kmalloc(len, type);
> + if (!s)
> + return NULL;
> +
> + memcpy(s, str, len);
> + s[len - 1] = '\0';
Very nitty, but technically the above memcpy() could pass "len - 1", right?
It doesn't really matter other than the wasteful copy of 1-byte, so:
Reviewed-by: Douglas Anderson <dianders@xxxxxxxxxxxx>