[PATCH v2 1/4] trace-cmd library: Do not use strncmp() when searching for KVM debug files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Using strncmp() when looking for KVM debug files with given names in
the debugfs is useless and could be dangerous, strcmp() should be
used instead. Limiting the string compare to the name of the searched
file only could bring problems, in case of files with overlapping
names.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@xxxxxxxxx>
---
 lib/trace-cmd/trace-timesync-kvm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/trace-cmd/trace-timesync-kvm.c b/lib/trace-cmd/trace-timesync-kvm.c
index 58c028ea..6f76fe1f 100644
--- a/lib/trace-cmd/trace-timesync-kvm.c
+++ b/lib/trace-cmd/trace-timesync-kvm.c
@@ -163,14 +163,12 @@ static int kvm_open_vcpu_dir(struct kvm_clock_sync *kvm, int cpu, char *dir_str)
 		goto error;
 	while ((entry = readdir(dir))) {
 		if (entry->d_type != DT_DIR) {
-			if (!strncmp(entry->d_name, KVM_DEBUG_OFFSET_FILE,
-				     strlen(KVM_DEBUG_OFFSET_FILE))) {
+			if (!strcmp(entry->d_name, KVM_DEBUG_OFFSET_FILE)) {
 				snprintf(path, sizeof(path), "%s/%s",
 					 dir_str, entry->d_name);
 				kvm->vcpu_offsets[cpu] = strdup(path);
 			}
-			if (!strncmp(entry->d_name, KVM_DEBUG_SCALING_FILE,
-				     strlen(KVM_DEBUG_SCALING_FILE))) {
+			if (!strcmp(entry->d_name, KVM_DEBUG_SCALING_FILE)) {
 				snprintf(path, sizeof(path), "%s/%s",
 					 dir_str, entry->d_name);
 				kvm->vcpu_scalings[cpu] = strdup(path);
-- 
2.31.1




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux