2012-11-09 14:04:52

by Tomas Hozza

[permalink] [raw]
Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory

Initial patch by Ben Hutchings <[email protected]>

We will install this in /usr, so it must use /var/lib for its state.
Only programs installed under /opt should use /var/opt.

Signed-off-by: Tomas Hozza <[email protected]>
---
tools/hv/hv_kvp_daemon.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 54ecb95..d9b3a74 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -98,7 +98,7 @@ static struct utsname uts_buf;
* The location of the interface configuration file.
*/

-#define KVP_CONFIG_LOC "/var/opt/"
+#define KVP_CONFIG_LOC "/var/lib/"

#define MAX_FILE_NAME 100
#define ENTRIES_PER_BLOCK 50
@@ -235,9 +235,9 @@ static int kvp_file_init(void)
int i;
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;

- if (access("/var/opt/hyperv", F_OK)) {
- if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
- syslog(LOG_ERR, " Failed to create /var/opt/hyperv");
+ if (access("/var/lib/hyperv", F_OK)) {
+ if (mkdir("/var/lib/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
+ syslog(LOG_ERR, " Failed to create /var/lib/hyperv");
exit(EXIT_FAILURE);
}
}
@@ -246,7 +246,7 @@ static int kvp_file_init(void)
fname = kvp_file_info[i].fname;
records_read = 0;
num_blocks = 1;
- sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i);
+ sprintf(fname, "/var/lib/hyperv/.kvp_pool_%d", i);
fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);

if (fd == -1)
--
1.7.11.7


2012-11-09 14:03:37

by Tomas Hozza

[permalink] [raw]
Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files

From: Ben Hutchings <[email protected]>

It's silly to create directories without execute permission, or to
give permissions to 'other' but not the group-owner.

Write the permissions in octal and 'ls -l' format since these are much
easier to read than the named macros.

Signed-off-by: Ben Hutchings <[email protected]>
Signed-off-by: Tomas Hozza <[email protected]>
---
tools/hv/hv_kvp_daemon.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 573b9aa..9609858 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -236,7 +236,7 @@ static int kvp_file_init(void)
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;

if (access("/var/lib/hyperv", F_OK)) {
- if (mkdir("/var/lib/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
+ if (mkdir("/var/lib/hyperv", 0755 /* rwxr-xr-x */)) {
syslog(LOG_ERR, " Failed to create /var/lib/hyperv");
exit(EXIT_FAILURE);
}
@@ -247,7 +247,7 @@ static int kvp_file_init(void)
records_read = 0;
num_blocks = 1;
sprintf(fname, "/var/lib/hyperv/.kvp_pool_%d", i);
- fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
+ fd = open(fname, O_RDWR | O_CREAT, 0644 /* rw-r--r-- */);

if (fd == -1)
return 1;
--
1.7.11.7

2012-11-09 14:07:35

by Tomas Hozza

[permalink] [raw]
Subject: [PATCH 2/3] tools/hv: Fix string types

Initial patch by Ben Hutchings <[email protected]>

Standard C strings are arrays of char, not __u8 (unsigned char).
Declare variables and parameters accordingly, and add the necessary
casts.

Signed-off-by: Tomas Hozza <[email protected]>
---
tools/hv/hv_kvp_daemon.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index d9b3a74..573b9aa 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -300,7 +300,7 @@ static int kvp_file_init(void)
return 0;
}

-static int kvp_key_delete(int pool, __u8 *key, int key_size)
+static int kvp_key_delete(int pool, const char *key, int key_size)
{
int i;
int j, k;
@@ -343,7 +343,7 @@ static int kvp_key_delete(int pool, __u8 *key, int key_size)
return 1;
}

-static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8 *value,
+static int kvp_key_add_or_modify(int pool, const char *key, int key_size, const char *value,
int value_size)
{
int i;
@@ -397,7 +397,7 @@ static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8 *value,
return 0;
}

-static int kvp_get_value(int pool, __u8 *key, int key_size, __u8 *value,
+static int kvp_get_value(int pool, const char *key, int key_size, char *value,
int value_size)
{
int i;
@@ -429,8 +429,8 @@ static int kvp_get_value(int pool, __u8 *key, int key_size, __u8 *value,
return 1;
}

-static int kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size,
- __u8 *value, int value_size)
+static int kvp_pool_enumerate(int pool, int index, char *key, int key_size,
+ char *value, int value_size)
{
struct kvp_record *record;

--
1.7.11.7

2012-11-09 15:53:36

by KY Srinivasan

[permalink] [raw]
Subject: RE: [PATCH 3/3] tools/hv: Fix permissions of created directory and files



> -----Original Message-----
> From: Tomas Hozza [mailto:[email protected]]
> Sent: Friday, November 09, 2012 9:01 AM
> To: [email protected]; KY Srinivasan; [email protected]; linux-
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]
> Cc: Tomas Hozza
> Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
>
> From: Ben Hutchings <[email protected]>
>
> It's silly to create directories without execute permission, or to
> give permissions to 'other' but not the group-owner.
>
> Write the permissions in octal and 'ls -l' format since these are much
> easier to read than the named macros.
>
> Signed-off-by: Ben Hutchings <[email protected]>
> Signed-off-by: Tomas Hozza <[email protected]>

Acked-by: K. Y. Srinivasan <[email protected]>
> ---
> tools/hv/hv_kvp_daemon.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index 573b9aa..9609858 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -236,7 +236,7 @@ static int kvp_file_init(void)
> int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
>
> if (access("/var/lib/hyperv", F_OK)) {
> - if (mkdir("/var/lib/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
> + if (mkdir("/var/lib/hyperv", 0755 /* rwxr-xr-x */)) {
> syslog(LOG_ERR, " Failed to create /var/lib/hyperv");
> exit(EXIT_FAILURE);
> }
> @@ -247,7 +247,7 @@ static int kvp_file_init(void)
> records_read = 0;
> num_blocks = 1;
> sprintf(fname, "/var/lib/hyperv/.kvp_pool_%d", i);
> - fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR |
> S_IROTH);
> + fd = open(fname, O_RDWR | O_CREAT, 0644 /* rw-r--r-- */);
>
> if (fd == -1)
> return 1;
> --
> 1.7.11.7
>
>

2012-11-09 15:56:58

by KY Srinivasan

[permalink] [raw]
Subject: RE: [PATCH 1/3] tools/hv: Fix /var subdirectory



> -----Original Message-----
> From: Tomas Hozza [mailto:[email protected]]
> Sent: Friday, November 09, 2012 9:01 AM
> To: [email protected]; KY Srinivasan; [email protected]; linux-
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]
> Cc: Tomas Hozza
> Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory
>
> Initial patch by Ben Hutchings <[email protected]>
>
> We will install this in /usr, so it must use /var/lib for its state.
> Only programs installed under /opt should use /var/opt.
>
> Signed-off-by: Tomas Hozza <[email protected]>
> ---
> tools/hv/hv_kvp_daemon.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index 54ecb95..d9b3a74 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -98,7 +98,7 @@ static struct utsname uts_buf;
> * The location of the interface configuration file.
> */
>
> -#define KVP_CONFIG_LOC "/var/opt/"
> +#define KVP_CONFIG_LOC "/var/lib/"
>
> #define MAX_FILE_NAME 100
> #define ENTRIES_PER_BLOCK 50
> @@ -235,9 +235,9 @@ static int kvp_file_init(void)
> int i;
> int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
>
> - if (access("/var/opt/hyperv", F_OK)) {
> - if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
> - syslog(LOG_ERR, " Failed to create /var/opt/hyperv");
> + if (access("/var/lib/hyperv", F_OK)) {
> + if (mkdir("/var/lib/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
> + syslog(LOG_ERR, " Failed to create /var/lib/hyperv");

Why don't you use the macro defined earlier for the path for /var/lib. Why
not include the hyperv directory as well in the macro.

Regards,

K. Y
> exit(EXIT_FAILURE);
> }
> }
> @@ -246,7 +246,7 @@ static int kvp_file_init(void)
> fname = kvp_file_info[i].fname;
> records_read = 0;
> num_blocks = 1;
> - sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i);
> + sprintf(fname, "/var/lib/hyperv/.kvp_pool_%d", i);
> fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR |
> S_IROTH);
>
> if (fd == -1)
> --
> 1.7.11.7
>
>

2012-11-09 15:57:36

by KY Srinivasan

[permalink] [raw]
Subject: RE: [PATCH 2/3] tools/hv: Fix string types



> -----Original Message-----
> From: Tomas Hozza [mailto:[email protected]]
> Sent: Friday, November 09, 2012 9:01 AM
> To: [email protected]; KY Srinivasan; [email protected]; linux-
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]
> Cc: Tomas Hozza
> Subject: [PATCH 2/3] tools/hv: Fix string types
>
> Initial patch by Ben Hutchings <[email protected]>
>
> Standard C strings are arrays of char, not __u8 (unsigned char).
> Declare variables and parameters accordingly, and add the necessary
> casts.
>
> Signed-off-by: Tomas Hozza <[email protected]>
Acked-by: K. Y. Srinivasan <[email protected]>
> ---
> tools/hv/hv_kvp_daemon.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index d9b3a74..573b9aa 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -300,7 +300,7 @@ static int kvp_file_init(void)
> return 0;
> }
>
> -static int kvp_key_delete(int pool, __u8 *key, int key_size)
> +static int kvp_key_delete(int pool, const char *key, int key_size)
> {
> int i;
> int j, k;
> @@ -343,7 +343,7 @@ static int kvp_key_delete(int pool, __u8 *key, int
> key_size)
> return 1;
> }
>
> -static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8
> *value,
> +static int kvp_key_add_or_modify(int pool, const char *key, int key_size, const
> char *value,
> int value_size)
> {
> int i;
> @@ -397,7 +397,7 @@ static int kvp_key_add_or_modify(int pool, __u8 *key, int
> key_size, __u8 *value,
> return 0;
> }
>
> -static int kvp_get_value(int pool, __u8 *key, int key_size, __u8 *value,
> +static int kvp_get_value(int pool, const char *key, int key_size, char *value,
> int value_size)
> {
> int i;
> @@ -429,8 +429,8 @@ static int kvp_get_value(int pool, __u8 *key, int key_size,
> __u8 *value,
> return 1;
> }
>
> -static int kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size,
> - __u8 *value, int value_size)
> +static int kvp_pool_enumerate(int pool, int index, char *key, int key_size,
> + char *value, int value_size)
> {
> struct kvp_record *record;
>
> --
> 1.7.11.7
>
>

2012-11-09 15:58:37

by KY Srinivasan

[permalink] [raw]
Subject: RE: [PATCH 3/3] tools/hv: Fix permissions of created directory and files



> -----Original Message-----
> From: Tomas Hozza [mailto:[email protected]]
> Sent: Friday, November 09, 2012 9:01 AM
> To: [email protected]; KY Srinivasan; [email protected]; linux-
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]
> Cc: Tomas Hozza
> Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
>
> From: Ben Hutchings <[email protected]>
>
> It's silly to create directories without execute permission, or to
> give permissions to 'other' but not the group-owner.
>
> Write the permissions in octal and 'ls -l' format since these are much
> easier to read than the named macros.
>
> Signed-off-by: Ben Hutchings <[email protected]>
> Signed-off-by: Tomas Hozza <[email protected]>
Acked-by: K. Y. Srinivasan <[email protected]>
> ---
> tools/hv/hv_kvp_daemon.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index 573b9aa..9609858 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -236,7 +236,7 @@ static int kvp_file_init(void)
> int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
>
> if (access("/var/lib/hyperv", F_OK)) {
> - if (mkdir("/var/lib/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
> + if (mkdir("/var/lib/hyperv", 0755 /* rwxr-xr-x */)) {
> syslog(LOG_ERR, " Failed to create /var/lib/hyperv");
> exit(EXIT_FAILURE);
> }
> @@ -247,7 +247,7 @@ static int kvp_file_init(void)
> records_read = 0;
> num_blocks = 1;
> sprintf(fname, "/var/lib/hyperv/.kvp_pool_%d", i);
> - fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR |
> S_IROTH);
> + fd = open(fname, O_RDWR | O_CREAT, 0644 /* rw-r--r-- */);
>
> if (fd == -1)
> return 1;
> --
> 1.7.11.7
>
>

2012-11-12 08:56:00

by Tomas Hozza

[permalink] [raw]
Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory

Initial patch by Ben Hutchings <[email protected]>

We will install this in /usr, so it must use /var/lib for its state.
Only programs installed under /opt should use /var/opt.

Signed-off-by: Tomas Hozza <[email protected]>
---
tools/hv/hv_kvp_daemon.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 54ecb95..d80a612 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -98,7 +98,7 @@ static struct utsname uts_buf;
* The location of the interface configuration file.
*/

-#define KVP_CONFIG_LOC "/var/opt/"
+#define KVP_CONFIG_LOC "/var/lib/hyperv"

#define MAX_FILE_NAME 100
#define ENTRIES_PER_BLOCK 50
@@ -235,9 +235,9 @@ static int kvp_file_init(void)
int i;
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;

- if (access("/var/opt/hyperv", F_OK)) {
- if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
- syslog(LOG_ERR, " Failed to create /var/opt/hyperv");
+ if (access(KVP_CONFIG_LOC, F_OK)) {
+ if (mkdir(KVP_CONFIG_LOC, S_IRUSR | S_IWUSR | S_IROTH)) {
+ syslog(LOG_ERR, " Failed to create %s", KVP_CONFIG_LOC);
exit(EXIT_FAILURE);
}
}
@@ -246,7 +246,7 @@ static int kvp_file_init(void)
fname = kvp_file_info[i].fname;
records_read = 0;
num_blocks = 1;
- sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i);
+ sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i);
fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);

if (fd == -1)
@@ -1263,7 +1263,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
*/

snprintf(if_file, sizeof(if_file), "%s%s%s", KVP_CONFIG_LOC,
- "hyperv/ifcfg-", if_name);
+ "/ifcfg-", if_name);

file = fopen(if_file, "w");

--
1.7.11.7

2012-11-12 08:56:18

by Tomas Hozza

[permalink] [raw]
Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files

From: Ben Hutchings <[email protected]>

It's silly to create directories without execute permission, or to
give permissions to 'other' but not the group-owner.

Write the permissions in octal and 'ls -l' format since these are much
easier to read than the named macros.

Signed-off-by: Ben Hutchings <[email protected]>
Signed-off-by: Tomas Hozza <[email protected]>
---
tools/hv/hv_kvp_daemon.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index a581b3f..17703c7 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -236,7 +236,7 @@ static int kvp_file_init(void)
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;

if (access(KVP_CONFIG_LOC, F_OK)) {
- if (mkdir(KVP_CONFIG_LOC, S_IRUSR | S_IWUSR | S_IROTH)) {
+ if (mkdir(KVP_CONFIG_LOC, 0755 /* rwxr-xr-x */)) {
syslog(LOG_ERR, " Failed to create %s", KVP_CONFIG_LOC);
exit(EXIT_FAILURE);
}
@@ -247,7 +247,7 @@ static int kvp_file_init(void)
records_read = 0;
num_blocks = 1;
sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i);
- fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
+ fd = open(fname, O_RDWR | O_CREAT, 0644 /* rw-r--r-- */);

if (fd == -1)
return 1;
--
1.7.11.7

2012-11-15 23:38:08

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/3] tools/hv: Fix /var subdirectory

On Fri, Nov 09, 2012 at 03:56:14PM +0000, KY Srinivasan wrote:
> > -----Original Message-----
> > From: Tomas Hozza [mailto:[email protected]]

<snip>

KY, there have been a few of these tools/hv patches floating by, and you
haven't acked all of them from what I can tell. I've applied some of
them, but I know I've missed some. Can you please resend the ones I've
missed that Tomas has sent, but I've not applied?

thanks,

greg k-h

2012-11-15 23:53:36

by KY Srinivasan

[permalink] [raw]
Subject: RE: [PATCH 1/3] tools/hv: Fix /var subdirectory



> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: Thursday, November 15, 2012 6:38 PM
> To: KY Srinivasan
> Cc: Tomas Hozza; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]
> Subject: Re: [PATCH 1/3] tools/hv: Fix /var subdirectory
>
> On Fri, Nov 09, 2012 at 03:56:14PM +0000, KY Srinivasan wrote:
> > > -----Original Message-----
> > > From: Tomas Hozza [mailto:[email protected]]
>
> <snip>
>
> KY, there have been a few of these tools/hv patches floating by, and you
> haven't acked all of them from what I can tell. I've applied some of
> them, but I know I've missed some. Can you please resend the ones I've
> missed that Tomas has sent, but I've not applied?

Will do. I am currently travelling in China and should be back in NJ this weekend. I will
handle these after I get back to NJ.

Regards,

K. Y
>
> thanks,
>
> greg k-h
>

2012-11-26 20:41:01

by KY Srinivasan

[permalink] [raw]
Subject: RE: [PATCH 3/3] tools/hv: Fix permissions of created directory and files



> -----Original Message-----
> From: Tomas Hozza [mailto:[email protected]]
> Sent: Monday, November 12, 2012 3:55 AM
> To: [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; KY Srinivasan; [email protected]
> Cc: Tomas Hozza
> Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
>
> From: Ben Hutchings <[email protected]>
>
> It's silly to create directories without execute permission, or to
> give permissions to 'other' but not the group-owner.
>
> Write the permissions in octal and 'ls -l' format since these are much
> easier to read than the named macros.
>
> Signed-off-by: Ben Hutchings <[email protected]>
> Signed-off-by: Tomas Hozza <[email protected]>
Acked-by: K. Y. Srinivasan <[email protected]>

> ---
> tools/hv/hv_kvp_daemon.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index a581b3f..17703c7 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -236,7 +236,7 @@ static int kvp_file_init(void)
> int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
>
> if (access(KVP_CONFIG_LOC, F_OK)) {
> - if (mkdir(KVP_CONFIG_LOC, S_IRUSR | S_IWUSR | S_IROTH)) {
> + if (mkdir(KVP_CONFIG_LOC, 0755 /* rwxr-xr-x */)) {
> syslog(LOG_ERR, " Failed to create %s",
> KVP_CONFIG_LOC);
> exit(EXIT_FAILURE);
> }
> @@ -247,7 +247,7 @@ static int kvp_file_init(void)
> records_read = 0;
> num_blocks = 1;
> sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i);
> - fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR |
> S_IROTH);
> + fd = open(fname, O_RDWR | O_CREAT, 0644 /* rw-r--r-- */);
>
> if (fd == -1)
> return 1;
> --
> 1.7.11.7


2012-11-26 20:43:00

by KY Srinivasan

[permalink] [raw]
Subject: RE: [PATCH 1/3] tools/hv: Fix /var subdirectory



> -----Original Message-----
> From: Tomas Hozza [mailto:[email protected]]
> Sent: Monday, November 12, 2012 3:55 AM
> To: [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; KY Srinivasan; [email protected]
> Cc: Tomas Hozza
> Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory
>
> Initial patch by Ben Hutchings <[email protected]>
>
> We will install this in /usr, so it must use /var/lib for its state.
> Only programs installed under /opt should use /var/opt.
>
> Signed-off-by: Tomas Hozza <[email protected]>
Acked-by: K. Y. Srinivasan <[email protected]>


> ---
> tools/hv/hv_kvp_daemon.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index 54ecb95..d80a612 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -98,7 +98,7 @@ static struct utsname uts_buf;
> * The location of the interface configuration file.
> */
>
> -#define KVP_CONFIG_LOC "/var/opt/"
> +#define KVP_CONFIG_LOC "/var/lib/hyperv"
>
> #define MAX_FILE_NAME 100
> #define ENTRIES_PER_BLOCK 50
> @@ -235,9 +235,9 @@ static int kvp_file_init(void)
> int i;
> int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
>
> - if (access("/var/opt/hyperv", F_OK)) {
> - if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
> - syslog(LOG_ERR, " Failed to create /var/opt/hyperv");
> + if (access(KVP_CONFIG_LOC, F_OK)) {
> + if (mkdir(KVP_CONFIG_LOC, S_IRUSR | S_IWUSR | S_IROTH)) {
> + syslog(LOG_ERR, " Failed to create %s",
> KVP_CONFIG_LOC);
> exit(EXIT_FAILURE);
> }
> }
> @@ -246,7 +246,7 @@ static int kvp_file_init(void)
> fname = kvp_file_info[i].fname;
> records_read = 0;
> num_blocks = 1;
> - sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i);
> + sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i);
> fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR |
> S_IROTH);
>
> if (fd == -1)
> @@ -1263,7 +1263,7 @@ static int kvp_set_ip_info(char *if_name, struct
> hv_kvp_ipaddr_value *new_val)
> */
>
> snprintf(if_file, sizeof(if_file), "%s%s%s", KVP_CONFIG_LOC,
> - "hyperv/ifcfg-", if_name);
> + "/ifcfg-", if_name);
>
> file = fopen(if_file, "w");
>
> --
> 1.7.11.7


2012-11-26 21:12:17

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/3] tools/hv: Fix /var subdirectory

On Mon, Nov 26, 2012 at 08:42:40PM +0000, KY Srinivasan wrote:
>
>
> > -----Original Message-----
> > From: Tomas Hozza [mailto:[email protected]]
> > Sent: Monday, November 12, 2012 3:55 AM
> > To: [email protected]; [email protected];
> > [email protected]; [email protected]; [email protected];
> > [email protected]; KY Srinivasan; [email protected]
> > Cc: Tomas Hozza
> > Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory
> >
> > Initial patch by Ben Hutchings <[email protected]>
> >
> > We will install this in /usr, so it must use /var/lib for its state.
> > Only programs installed under /opt should use /var/opt.
> >
> > Signed-off-by: Tomas Hozza <[email protected]>
> Acked-by: K. Y. Srinivasan <[email protected]>

As I stated before, you need to rediff these, and resend them to me, I
have no more hyperv patches in my queue to apply.

greg k-h

2012-11-26 21:16:10

by KY Srinivasan

[permalink] [raw]
Subject: RE: [PATCH 1/3] tools/hv: Fix /var subdirectory



> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: Monday, November 26, 2012 4:12 PM
> To: KY Srinivasan
> Cc: Tomas Hozza; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]
> Subject: Re: [PATCH 1/3] tools/hv: Fix /var subdirectory
>
> On Mon, Nov 26, 2012 at 08:42:40PM +0000, KY Srinivasan wrote:
> >
> >
> > > -----Original Message-----
> > > From: Tomas Hozza [mailto:[email protected]]
> > > Sent: Monday, November 12, 2012 3:55 AM
> > > To: [email protected]; [email protected];
> > > [email protected]; [email protected]; [email protected];
> > > [email protected]; KY Srinivasan; [email protected]
> > > Cc: Tomas Hozza
> > > Subject: [PATCH 1/3] tools/hv: Fix /var subdirectory
> > >
> > > Initial patch by Ben Hutchings <[email protected]>
> > >
> > > We will install this in /usr, so it must use /var/lib for its state.
> > > Only programs installed under /opt should use /var/opt.
> > >
> > > Signed-off-by: Tomas Hozza <[email protected]>
> > Acked-by: K. Y. Srinivasan <[email protected]>
>
> As I stated before, you need to rediff these, and resend them to me, I
> have no more hyperv patches in my queue to apply.

Will do. There were totally 3 patches that Tomas had sent that I acked today. Tomas, could you
rebase the patches (if needed) and re-send them.

K. Y
>
> greg k-h
>


2012-11-27 07:57:07

by Tomas Hozza

[permalink] [raw]
Subject: [PATCH 1/3] tools/hv: Fix for long file names from readdir

kvp_get_if_name and kvp_mac_to_if_name copy strings into statically
sized buffers which could be too small to store really long names.

Buffer sizes have been changed to PATH_MAX, include "limits.h" where
PATH_MAX is defined was added and length checks ware added via snprintf.

Signed-off-by: Tomas Hozza <[email protected]>
---
tools/hv/hv_kvp_daemon.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index d25a469..90f1f07 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -44,6 +44,7 @@
#include <fcntl.h>
#include <dirent.h>
#include <net/if.h>
+#include <limits.h>

/*
* KVP protocol: The user mode component first registers with the
@@ -592,26 +593,22 @@ static char *kvp_get_if_name(char *guid)
DIR *dir;
struct dirent *entry;
FILE *file;
- char *p, *q, *x;
+ char *p, *x;
char *if_name = NULL;
char buf[256];
char *kvp_net_dir = "/sys/class/net/";
- char dev_id[256];
+ char dev_id[PATH_MAX];

dir = opendir(kvp_net_dir);
if (dir == NULL)
return NULL;

- snprintf(dev_id, sizeof(dev_id), "%s", kvp_net_dir);
- q = dev_id + strlen(kvp_net_dir);
-
while ((entry = readdir(dir)) != NULL) {
/*
* Set the state for the next pass.
*/
- *q = '\0';
- strcat(dev_id, entry->d_name);
- strcat(dev_id, "/device/device_id");
+ snprintf(dev_id, sizeof(dev_id), "%s%s/device/device_id", kvp_net_dir,
+ entry->d_name);

file = fopen(dev_id, "r");
if (file == NULL)
@@ -684,28 +681,23 @@ static char *kvp_mac_to_if_name(char *mac)
DIR *dir;
struct dirent *entry;
FILE *file;
- char *p, *q, *x;
+ char *p, *x;
char *if_name = NULL;
char buf[256];
char *kvp_net_dir = "/sys/class/net/";
- char dev_id[256];
+ char dev_id[PATH_MAX];
int i;

dir = opendir(kvp_net_dir);
if (dir == NULL)
return NULL;

- snprintf(dev_id, sizeof(dev_id), kvp_net_dir);
- q = dev_id + strlen(kvp_net_dir);
-
while ((entry = readdir(dir)) != NULL) {
/*
* Set the state for the next pass.
*/
- *q = '\0';
-
- strcat(dev_id, entry->d_name);
- strcat(dev_id, "/address");
+ snprintf(dev_id, sizeof(dev_id), "%s%s/address", kvp_net_dir,
+ entry->d_name);

file = fopen(dev_id, "r");
if (file == NULL)
--
1.7.11.7

2012-11-27 07:57:19

by Tomas Hozza

[permalink] [raw]
Subject: [PATCH 2/3] tools/hv: Fix /var subdirectory

Initial patch by Ben Hutchings <[email protected]>

We will install this in /usr, so it must use /var/lib for its state.
Only programs installed under /opt should use /var/opt.

Signed-off-by: Tomas Hozza <[email protected]>
---
tools/hv/hv_kvp_daemon.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 90f1f07..e266251 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -98,7 +98,7 @@ static struct utsname uts_buf;
* The location of the interface configuration file.
*/

-#define KVP_CONFIG_LOC "/var/opt/"
+#define KVP_CONFIG_LOC "/var/lib/hyperv"

#define MAX_FILE_NAME 100
#define ENTRIES_PER_BLOCK 50
@@ -235,9 +235,9 @@ static int kvp_file_init(void)
int i;
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;

- if (access("/var/opt/hyperv", F_OK)) {
- if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
- syslog(LOG_ERR, " Failed to create /var/opt/hyperv");
+ if (access(KVP_CONFIG_LOC, F_OK)) {
+ if (mkdir(KVP_CONFIG_LOC, S_IRUSR | S_IWUSR | S_IROTH)) {
+ syslog(LOG_ERR, " Failed to create %s", KVP_CONFIG_LOC);
exit(EXIT_FAILURE);
}
}
@@ -246,7 +246,7 @@ static int kvp_file_init(void)
fname = kvp_file_info[i].fname;
records_read = 0;
num_blocks = 1;
- sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i);
+ sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i);
fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);

if (fd == -1)
@@ -1263,7 +1263,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
*/

snprintf(if_file, sizeof(if_file), "%s%s%s", KVP_CONFIG_LOC,
- "hyperv/ifcfg-", if_name);
+ "/ifcfg-", if_name);

file = fopen(if_file, "w");

--
1.7.11.7

2012-11-27 07:57:28

by Tomas Hozza

[permalink] [raw]
Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files

From: Ben Hutchings <[email protected]>

It's silly to create directories without execute permission, or to
give permissions to 'other' but not the group-owner.

Write the permissions in octal and 'ls -l' format since these are much
easier to read than the named macros.

Signed-off-by: Ben Hutchings <[email protected]>
Signed-off-by: Tomas Hozza <[email protected]>
---
tools/hv/hv_kvp_daemon.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index e266251..7105c7b 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -236,7 +236,7 @@ static int kvp_file_init(void)
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;

if (access(KVP_CONFIG_LOC, F_OK)) {
- if (mkdir(KVP_CONFIG_LOC, S_IRUSR | S_IWUSR | S_IROTH)) {
+ if (mkdir(KVP_CONFIG_LOC, 0755 /* rwxr-xr-x */)) {
syslog(LOG_ERR, " Failed to create %s", KVP_CONFIG_LOC);
exit(EXIT_FAILURE);
}
@@ -247,7 +247,7 @@ static int kvp_file_init(void)
records_read = 0;
num_blocks = 1;
sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i);
- fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
+ fd = open(fname, O_RDWR | O_CREAT, 0644 /* rw-r--r-- */);

if (fd == -1)
return 1;
--
1.7.11.7

2012-11-27 13:59:20

by KY Srinivasan

[permalink] [raw]
Subject: RE: [PATCH 1/3] tools/hv: Fix for long file names from readdir



> -----Original Message-----
> From: Tomas Hozza [mailto:[email protected]]
> Sent: Tuesday, November 27, 2012 2:57 AM
> To: [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; KY Srinivasan; [email protected]
> Cc: Tomas Hozza
> Subject: [PATCH 1/3] tools/hv: Fix for long file names from readdir
>
> kvp_get_if_name and kvp_mac_to_if_name copy strings into statically
> sized buffers which could be too small to store really long names.
>
> Buffer sizes have been changed to PATH_MAX, include "limits.h" where
> PATH_MAX is defined was added and length checks ware added via snprintf.
>
> Signed-off-by: Tomas Hozza <[email protected]>
Acked-by: K. Y. Srinivasan <[email protected]>

> ---
> tools/hv/hv_kvp_daemon.c | 26 +++++++++-----------------
> 1 file changed, 9 insertions(+), 17 deletions(-)
>
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index d25a469..90f1f07 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -44,6 +44,7 @@
> #include <fcntl.h>
> #include <dirent.h>
> #include <net/if.h>
> +#include <limits.h>
>
> /*
> * KVP protocol: The user mode component first registers with the
> @@ -592,26 +593,22 @@ static char *kvp_get_if_name(char *guid)
> DIR *dir;
> struct dirent *entry;
> FILE *file;
> - char *p, *q, *x;
> + char *p, *x;
> char *if_name = NULL;
> char buf[256];
> char *kvp_net_dir = "/sys/class/net/";
> - char dev_id[256];
> + char dev_id[PATH_MAX];
>
> dir = opendir(kvp_net_dir);
> if (dir == NULL)
> return NULL;
>
> - snprintf(dev_id, sizeof(dev_id), "%s", kvp_net_dir);
> - q = dev_id + strlen(kvp_net_dir);
> -
> while ((entry = readdir(dir)) != NULL) {
> /*
> * Set the state for the next pass.
> */
> - *q = '\0';
> - strcat(dev_id, entry->d_name);
> - strcat(dev_id, "/device/device_id");
> + snprintf(dev_id, sizeof(dev_id), "%s%s/device/device_id",
> kvp_net_dir,
> + entry->d_name);
>
> file = fopen(dev_id, "r");
> if (file == NULL)
> @@ -684,28 +681,23 @@ static char *kvp_mac_to_if_name(char *mac)
> DIR *dir;
> struct dirent *entry;
> FILE *file;
> - char *p, *q, *x;
> + char *p, *x;
> char *if_name = NULL;
> char buf[256];
> char *kvp_net_dir = "/sys/class/net/";
> - char dev_id[256];
> + char dev_id[PATH_MAX];
> int i;
>
> dir = opendir(kvp_net_dir);
> if (dir == NULL)
> return NULL;
>
> - snprintf(dev_id, sizeof(dev_id), kvp_net_dir);
> - q = dev_id + strlen(kvp_net_dir);
> -
> while ((entry = readdir(dir)) != NULL) {
> /*
> * Set the state for the next pass.
> */
> - *q = '\0';
> -
> - strcat(dev_id, entry->d_name);
> - strcat(dev_id, "/address");
> + snprintf(dev_id, sizeof(dev_id), "%s%s/address", kvp_net_dir,
> + entry->d_name);
>
> file = fopen(dev_id, "r");
> if (file == NULL)
> --
> 1.7.11.7
>
>


2012-11-27 14:10:45

by KY Srinivasan

[permalink] [raw]
Subject: RE: [PATCH 3/3] tools/hv: Fix permissions of created directory and files



> -----Original Message-----
> From: Tomas Hozza [mailto:[email protected]]
> Sent: Tuesday, November 27, 2012 2:57 AM
> To: [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; KY Srinivasan; [email protected]
> Cc: Tomas Hozza
> Subject: [PATCH 3/3] tools/hv: Fix permissions of created directory and files
>
> From: Ben Hutchings <[email protected]>
>
> It's silly to create directories without execute permission, or to
> give permissions to 'other' but not the group-owner.
>
> Write the permissions in octal and 'ls -l' format since these are much
> easier to read than the named macros.
>
> Signed-off-by: Ben Hutchings <[email protected]>
> Signed-off-by: Tomas Hozza <[email protected]>
Acked-by: K. Y. Srinivasan <[email protected]>

> ---
> tools/hv/hv_kvp_daemon.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index e266251..7105c7b 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -236,7 +236,7 @@ static int kvp_file_init(void)
> int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
>
> if (access(KVP_CONFIG_LOC, F_OK)) {
> - if (mkdir(KVP_CONFIG_LOC, S_IRUSR | S_IWUSR | S_IROTH)) {
> + if (mkdir(KVP_CONFIG_LOC, 0755 /* rwxr-xr-x */)) {
> syslog(LOG_ERR, " Failed to create %s",
> KVP_CONFIG_LOC);
> exit(EXIT_FAILURE);
> }
> @@ -247,7 +247,7 @@ static int kvp_file_init(void)
> records_read = 0;
> num_blocks = 1;
> sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i);
> - fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR |
> S_IROTH);
> + fd = open(fname, O_RDWR | O_CREAT, 0644 /* rw-r--r-- */);
>
> if (fd == -1)
> return 1;
> --
> 1.7.11.7
>
>


2012-11-27 14:17:04

by KY Srinivasan

[permalink] [raw]
Subject: RE: [PATCH 2/3] tools/hv: Fix /var subdirectory



> -----Original Message-----
> From: Tomas Hozza [mailto:[email protected]]
> Sent: Tuesday, November 27, 2012 2:57 AM
> To: [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; KY Srinivasan; [email protected]
> Cc: Tomas Hozza
> Subject: [PATCH 2/3] tools/hv: Fix /var subdirectory
>
> Initial patch by Ben Hutchings <[email protected]>
>
> We will install this in /usr, so it must use /var/lib for its state.
> Only programs installed under /opt should use /var/opt.
>
> Signed-off-by: Tomas Hozza <[email protected]>
Acked-by: K. Y. Srinivasan <[email protected]>

> ---
> tools/hv/hv_kvp_daemon.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
> index 90f1f07..e266251 100644
> --- a/tools/hv/hv_kvp_daemon.c
> +++ b/tools/hv/hv_kvp_daemon.c
> @@ -98,7 +98,7 @@ static struct utsname uts_buf;
> * The location of the interface configuration file.
> */
>
> -#define KVP_CONFIG_LOC "/var/opt/"
> +#define KVP_CONFIG_LOC "/var/lib/hyperv"
>
> #define MAX_FILE_NAME 100
> #define ENTRIES_PER_BLOCK 50
> @@ -235,9 +235,9 @@ static int kvp_file_init(void)
> int i;
> int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
>
> - if (access("/var/opt/hyperv", F_OK)) {
> - if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
> - syslog(LOG_ERR, " Failed to create /var/opt/hyperv");
> + if (access(KVP_CONFIG_LOC, F_OK)) {
> + if (mkdir(KVP_CONFIG_LOC, S_IRUSR | S_IWUSR | S_IROTH)) {
> + syslog(LOG_ERR, " Failed to create %s",
> KVP_CONFIG_LOC);
> exit(EXIT_FAILURE);
> }
> }
> @@ -246,7 +246,7 @@ static int kvp_file_init(void)
> fname = kvp_file_info[i].fname;
> records_read = 0;
> num_blocks = 1;
> - sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i);
> + sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i);
> fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR |
> S_IROTH);
>
> if (fd == -1)
> @@ -1263,7 +1263,7 @@ static int kvp_set_ip_info(char *if_name, struct
> hv_kvp_ipaddr_value *new_val)
> */
>
> snprintf(if_file, sizeof(if_file), "%s%s%s", KVP_CONFIG_LOC,
> - "hyperv/ifcfg-", if_name);
> + "/ifcfg-", if_name);
>
> file = fopen(if_file, "w");
>
> --
> 1.7.11.7
>
>


2012-11-27 14:50:54

by Ben Hutchings

[permalink] [raw]
Subject: Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir

On Tue, 2012-11-27 at 08:56 +0100, Tomas Hozza wrote:
> kvp_get_if_name and kvp_mac_to_if_name copy strings into statically
> sized buffers which could be too small to store really long names.
>
> Buffer sizes have been changed to PATH_MAX, include "limits.h" where
> PATH_MAX is defined was added and length checks ware added via snprintf.
[...]

PATH_MAX has nothing to do with any actual kernel limit; it's no more
meaningful than the current value of 256. Network interface names are
limited to 15 characters, thus the current array is more than long
enough. So I think this is entirely unnecessary.

Using snprintf() is a good idea, but you need to check the return value
and handle the truncation case somehow.

Ben.

--
Ben Hutchings
Never attribute to conspiracy what can adequately be explained by stupidity.


Attachments:
signature.asc (828.00 B)
This is a digitally signed message part

2012-11-27 20:28:43

by Tomas Hozza

[permalink] [raw]
Subject: Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir



----- Original Message -----
> On Tue, 2012-11-27 at 08:56 +0100, Tomas Hozza wrote:
> > kvp_get_if_name and kvp_mac_to_if_name copy strings into statically
> > sized buffers which could be too small to store really long names.
> >
> > Buffer sizes have been changed to PATH_MAX, include "limits.h"
> > where
> > PATH_MAX is defined was added and length checks ware added via
> > snprintf.
> [...]
>
> PATH_MAX has nothing to do with any actual kernel limit; it's no more
> meaningful than the current value of 256. Network interface names
> are
> limited to 15 characters, thus the current array is more than long
> enough. So I think this is entirely unnecessary.

This is just for sanity. The value PATH_MAX was chosen after discussion
with K. Y. Srinivasan and Olaf Hering instead of some "magic" number like
256 or 512.

> Using snprintf() is a good idea, but you need to check the return
> value and handle the truncation case somehow.

By using PATH_MAX sized buffer there is no need for handling the truncation
case.


Tomas Hozza

2012-11-27 20:41:20

by Ben Hutchings

[permalink] [raw]
Subject: Re: [PATCH 1/3] tools/hv: Fix for long file names from readdir

On Tue, Nov 27, 2012 at 03:28:25PM -0500, Tomas Hozza wrote:
>
>
> ----- Original Message -----
> > On Tue, 2012-11-27 at 08:56 +0100, Tomas Hozza wrote:
> > > kvp_get_if_name and kvp_mac_to_if_name copy strings into statically
> > > sized buffers which could be too small to store really long names.
> > >
> > > Buffer sizes have been changed to PATH_MAX, include "limits.h"
> > > where
> > > PATH_MAX is defined was added and length checks ware added via
> > > snprintf.
> > [...]
> >
> > PATH_MAX has nothing to do with any actual kernel limit; it's no more
> > meaningful than the current value of 256. Network interface names
> > are
> > limited to 15 characters, thus the current array is more than long
> > enough. So I think this is entirely unnecessary.
>
> This is just for sanity. The value PATH_MAX was chosen after discussion
> with K. Y. Srinivasan and Olaf Hering instead of some "magic" number like
> 256 or 512.

PATH_MAX is a magic name.

> > Using snprintf() is a good idea, but you need to check the return
> > value and handle the truncation case somehow.
>
> By using PATH_MAX sized buffer there is no need for handling the truncation
> case.

You are claiming two contradictory things: sprintf() may overrun the
buffer, so we need the length check provided by snprintf(), but there
is no need to check for truncation because we know the length is
sufficient.

Ben.

--
Ben Hutchings
We get into the habit of living before acquiring the habit of thinking.
- Albert Camus