mirror of
https://github.com/torvalds/linux.git
synced 2026-01-24 23:16:46 +00:00
kdb: Replace deprecated strcpy() with helper function in kdb_defcmd()
strcpy() is deprecated; use the new helper function kdb_strdup_dequote() instead. In addition to string duplication similar to kdb_strdup(), it also trims surrounding quotes from the input string if present. kdb_strdup_dequote() also checks for a trailing quote in the input string which was previously not checked. Link: https://github.com/KSPP/linux/issues/88 Reviewed-by: Douglas Anderson <dianders@chromium.org> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Signed-off-by: Daniel Thompson (RISCstar) <danielt@kernel.org>
This commit is contained in:
committed by
Daniel Thompson (RISCstar)
parent
5b26f1a314
commit
0c28a23722
@@ -721,20 +721,12 @@ static int kdb_defcmd(int argc, const char **argv)
|
||||
mp->name = kdb_strdup(argv[1], GFP_KDB);
|
||||
if (!mp->name)
|
||||
goto fail_name;
|
||||
mp->usage = kdb_strdup(argv[2], GFP_KDB);
|
||||
mp->usage = kdb_strdup_dequote(argv[2], GFP_KDB);
|
||||
if (!mp->usage)
|
||||
goto fail_usage;
|
||||
mp->help = kdb_strdup(argv[3], GFP_KDB);
|
||||
mp->help = kdb_strdup_dequote(argv[3], GFP_KDB);
|
||||
if (!mp->help)
|
||||
goto fail_help;
|
||||
if (mp->usage[0] == '"') {
|
||||
strcpy(mp->usage, argv[2]+1);
|
||||
mp->usage[strlen(mp->usage)-1] = '\0';
|
||||
}
|
||||
if (mp->help[0] == '"') {
|
||||
strcpy(mp->help, argv[3]+1);
|
||||
mp->help[strlen(mp->help)-1] = '\0';
|
||||
}
|
||||
|
||||
INIT_LIST_HEAD(&kdb_macro->statements);
|
||||
defcmd_in_progress = true;
|
||||
|
||||
@@ -110,6 +110,7 @@ extern int kdbgetaddrarg(int, const char **, int*, unsigned long *,
|
||||
extern int kdbgetsymval(const char *, kdb_symtab_t *);
|
||||
extern int kdbnearsym(unsigned long, kdb_symtab_t *);
|
||||
extern char *kdb_strdup(const char *str, gfp_t type);
|
||||
extern char *kdb_strdup_dequote(const char *str, gfp_t type);
|
||||
extern void kdb_symbol_print(unsigned long, const kdb_symtab_t *, unsigned int);
|
||||
|
||||
/* Routine for debugging the debugger state. */
|
||||
|
||||
@@ -255,6 +255,35 @@ char *kdb_strdup(const char *str, gfp_t type)
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 - 1);
|
||||
s[len - 1] = '\0';
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* kdb_getarea_size - Read an area of data. The kdb equivalent of
|
||||
* copy_from_user, with kdb messages for invalid addresses.
|
||||
|
||||
Reference in New Issue
Block a user