mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 11:11:45 -04:00
libsubcmd: Fix memory leak in uniq()
[ Upstream commit ad30469a841b50dbb541df4d6971d891f703c297 ] uniq() will write one command name over another causing the overwritten string to be leaked. Fix by doing a pass that removes duplicates and a second that removes the holes. Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Chenyuan Mi <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
This commit is contained in:
parent
3e06e9b906
commit
884b746209
1 changed files with 14 additions and 4 deletions
|
|
@ -50,11 +50,21 @@ void uniq(struct cmdnames *cmds)
|
|||
if (!cmds->cnt)
|
||||
return;
|
||||
|
||||
for (i = j = 1; i < cmds->cnt; i++)
|
||||
if (strcmp(cmds->names[i]->name, cmds->names[i-1]->name))
|
||||
cmds->names[j++] = cmds->names[i];
|
||||
|
||||
for (i = 1; i < cmds->cnt; i++) {
|
||||
if (!strcmp(cmds->names[i]->name, cmds->names[i-1]->name))
|
||||
zfree(&cmds->names[i - 1]);
|
||||
}
|
||||
for (i = 0, j = 0; i < cmds->cnt; i++) {
|
||||
if (cmds->names[i]) {
|
||||
if (i == j)
|
||||
j++;
|
||||
else
|
||||
cmds->names[j++] = cmds->names[i];
|
||||
}
|
||||
}
|
||||
cmds->cnt = j;
|
||||
while (j < i)
|
||||
cmds->names[j++] = NULL;
|
||||
}
|
||||
|
||||
void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)
|
||||
|
|
|
|||
Loading…
Reference in a new issue