perf kvm: use strtol for walking guestmount directory
PATCH 1/1 perf kvm: use strtol for walking guestmount directory
Only want to process directories under the guestmnount directory that have a pid as a name (ie, all digits). Other entries in the guestmount directory should be ignored. There is already a check that requires the first character of each entry to be a digit, but atoi is used to convert the directory name to a pid. For example if guestmount contains a directory with the name 1foo, atoi converts it to a pid of 1 and a machine is created with a pid of 1. This is wrong; this directory really should be ignored. Use strtol to do that.
--- tools/perf/util/symbol.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
tools/perf/util/symbol.c +9 -1
@@ -2875,6 +2875,7 @@ int machines__create_guest_kernel_maps(struct rb_root *machines)int i, items =0 ;char path[PATH_MAX ];pid_t pid; +char *endp; if (symbol_conf.default_guest_vmlinux_name || symbol_conf.default_guest_modules ||
@@ -2891,7 +2892,14 @@ int machines__create_guest_kernel_maps(struct rb_root *machines)/* Filter out . and .. */ continue ; } - pid =atoi (namelist[i]->d_name); + pid = (pid_t )strtol (namelist[i]->d_name, &endp,10 ); +if ((*endp !='\0' ) || + (endp == namelist[i]->d_name) || + (errno ==ERANGE )) { +pr_debug ("invalid directory (%s). Skipping.\n" , + namelist[i]->d_name); +continue ; + }sprintf (path,"%s/%s/proc/kallsyms" , symbol_conf.guestmount, namelist[i]->d_name);
Signature · 1 line
1.7.10.1
[tip:perf/urgent] perf kvm: Use strtol for walking guestmount directory
Commit-ID: 347ed9903a10179d1cf733d5d77072b283d89da3 Gitweb: http://git.kernel.org/tip/347ed9903a10179d1cf733d5d77072b283d89da3 Author: David Ahern <[email protected]> AuthorDate: Sun, 29 Jul 2012 20:54:35 -0600 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 3 Aug 2012 10:35:23 -0300
perf kvm: Use strtol for walking guestmount directory
Only want to process directories under the guestmnount directory that have a pid as a name (ie, all digits). Other entries in the guestmount directory should be ignored. There is already a check that requires the first character of each entry to be a digit, but atoi is used to convert the directory name to a pid. For example if guestmount contains a directory with the name 1foo, atoi converts it to a pid of 1 and a machine is created with a pid of 1. This is wrong; this directory really should be ignored. Use strtol to do that.
--- tools/perf/util/symbol.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
tools/perf/util/symbol.c +9 -1
@@ -2875,6 +2875,7 @@ int machines__create_guest_kernel_maps(struct rb_root *machines)int i, items =0 ;char path[PATH_MAX ];pid_t pid; +char *endp; if (symbol_conf.default_guest_vmlinux_name || symbol_conf.default_guest_modules ||
@@ -2891,7 +2892,14 @@ int machines__create_guest_kernel_maps(struct rb_root *machines)/* Filter out . and .. */ continue ; } - pid =atoi (namelist[i]->d_name); + pid = (pid_t )strtol (namelist[i]->d_name, &endp,10 ); +if ((*endp !='\0' ) || + (endp == namelist[i]->d_name) || + (errno ==ERANGE )) { +pr_debug ("invalid directory (%s). Skipping.\n" , + namelist[i]->d_name); +continue ; + }sprintf (path,"%s/%s/proc/kallsyms" , symbol_conf.guestmount, namelist[i]->d_name);