|
|
7b0ce3 |
From 396ee697e4d5c7d10bacf6d4670fb4ddab357330 Mon Sep 17 00:00:00 2001
|
|
|
7b0ce3 |
From: Tomas Hozza <thozza@redhat.com>
|
|
|
7b0ce3 |
Date: Mon, 5 Nov 2012 13:56:02 +0100
|
|
|
7b0ce3 |
Subject: [PATCH] Tools: hv: Fix for long file names from readdir
|
|
|
7b0ce3 |
|
|
|
7b0ce3 |
kvp_get_if_name and kvp_mac_to_if_name copy strings into statically
|
|
|
7b0ce3 |
sized buffers which could be too small to store really long names.
|
|
|
7b0ce3 |
|
|
|
7b0ce3 |
Buffer sizes have been increased and length checks added via snprintf.
|
|
|
7b0ce3 |
---
|
|
|
7b0ce3 |
hv_kvp_daemon.c | 26 +++++++++-----------------
|
|
|
7b0ce3 |
1 file changed, 9 insertions(+), 17 deletions(-)
|
|
|
7b0ce3 |
|
|
|
7b0ce3 |
diff --git a/hv_kvp_daemon.c b/hv_kvp_daemon.c
|
|
|
7b0ce3 |
index 3ea3af2..4c2ab6a 100755
|
|
|
7b0ce3 |
--- a/hv_kvp_daemon.c
|
|
|
7b0ce3 |
+++ b/hv_kvp_daemon.c
|
|
|
7b0ce3 |
@@ -44,6 +44,7 @@
|
|
|
7b0ce3 |
#include <fcntl.h>
|
|
|
7b0ce3 |
#include <dirent.h>
|
|
|
7b0ce3 |
#include <net/if.h>
|
|
|
7b0ce3 |
+#include <limits.h>
|
|
|
7b0ce3 |
|
|
|
7b0ce3 |
/*
|
|
|
7b0ce3 |
* KVP protocol: The user mode component first registers with the
|
|
|
7b0ce3 |
@@ -588,26 +589,22 @@ static char *kvp_get_if_name(char *guid)
|
|
|
7b0ce3 |
DIR *dir;
|
|
|
7b0ce3 |
struct dirent *entry;
|
|
|
7b0ce3 |
FILE *file;
|
|
|
7b0ce3 |
- char *p, *q, *x;
|
|
|
7b0ce3 |
+ char *p, *x;
|
|
|
7b0ce3 |
char *if_name = NULL;
|
|
|
7b0ce3 |
char buf[256];
|
|
|
7b0ce3 |
char *kvp_net_dir = "/sys/class/net/";
|
|
|
7b0ce3 |
- char dev_id[256];
|
|
|
7b0ce3 |
+ char dev_id[PATH_MAX];
|
|
|
7b0ce3 |
|
|
|
7b0ce3 |
dir = opendir(kvp_net_dir);
|
|
|
7b0ce3 |
if (dir == NULL)
|
|
|
7b0ce3 |
return NULL;
|
|
|
7b0ce3 |
|
|
|
7b0ce3 |
- snprintf(dev_id, sizeof(dev_id), "%s", kvp_net_dir);
|
|
|
7b0ce3 |
- q = dev_id + strlen(kvp_net_dir);
|
|
|
7b0ce3 |
-
|
|
|
7b0ce3 |
while ((entry = readdir(dir)) != NULL) {
|
|
|
7b0ce3 |
/*
|
|
|
7b0ce3 |
* Set the state for the next pass.
|
|
|
7b0ce3 |
*/
|
|
|
7b0ce3 |
- *q = '\0';
|
|
|
7b0ce3 |
- strcat(dev_id, entry->d_name);
|
|
|
7b0ce3 |
- strcat(dev_id, "/device/device_id");
|
|
|
7b0ce3 |
+ snprintf(dev_id, sizeof(dev_id), "%s%s/device/device_id", kvp_net_dir,
|
|
|
7b0ce3 |
+ entry->d_name);
|
|
|
7b0ce3 |
|
|
|
7b0ce3 |
file = fopen(dev_id, "r");
|
|
|
7b0ce3 |
if (file == NULL)
|
|
|
7b0ce3 |
@@ -680,28 +677,23 @@ static char *kvp_mac_to_if_name(char *mac)
|
|
|
7b0ce3 |
DIR *dir;
|
|
|
7b0ce3 |
struct dirent *entry;
|
|
|
7b0ce3 |
FILE *file;
|
|
|
7b0ce3 |
- char *p, *q, *x;
|
|
|
7b0ce3 |
+ char *p, *x;
|
|
|
7b0ce3 |
char *if_name = NULL;
|
|
|
7b0ce3 |
char buf[256];
|
|
|
7b0ce3 |
char *kvp_net_dir = "/sys/class/net/";
|
|
|
7b0ce3 |
- char dev_id[256];
|
|
|
7b0ce3 |
+ char dev_id[PATH_MAX];
|
|
|
7b0ce3 |
int i;
|
|
|
7b0ce3 |
|
|
|
7b0ce3 |
dir = opendir(kvp_net_dir);
|
|
|
7b0ce3 |
if (dir == NULL)
|
|
|
7b0ce3 |
return NULL;
|
|
|
7b0ce3 |
|
|
|
7b0ce3 |
- snprintf(dev_id, sizeof(dev_id), kvp_net_dir);
|
|
|
7b0ce3 |
- q = dev_id + strlen(kvp_net_dir);
|
|
|
7b0ce3 |
-
|
|
|
7b0ce3 |
while ((entry = readdir(dir)) != NULL) {
|
|
|
7b0ce3 |
/*
|
|
|
7b0ce3 |
* Set the state for the next pass.
|
|
|
7b0ce3 |
*/
|
|
|
7b0ce3 |
- *q = '\0';
|
|
|
7b0ce3 |
-
|
|
|
7b0ce3 |
- strcat(dev_id, entry->d_name);
|
|
|
7b0ce3 |
- strcat(dev_id, "/address");
|
|
|
7b0ce3 |
+ snprintf(dev_id, sizeof(dev_id), "%s%s/address", kvp_net_dir,
|
|
|
7b0ce3 |
+ entry->d_name);
|
|
|
7b0ce3 |
|
|
|
7b0ce3 |
file = fopen(dev_id, "r");
|
|
|
7b0ce3 |
if (file == NULL)
|
|
|
7b0ce3 |
--
|
|
|
7b0ce3 |
1.7.11.7
|
|
|
7b0ce3 |
|