diff mbox

[19/21] xfsprogs: Remove single byte array from struct parent

Message ID 1525754479-12177-20-git-send-email-allison.henderson@oracle.com (mailing list archive)
State Superseded
Headers show

Commit Message

Allison Henderson May 8, 2018, 4:41 a.m. UTC
Variable sized arrays implemented this way may cause
corruptions depending on how different compilers pack
the structure.

Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
---
 include/parent.h | 1 -
 io/parent.c      | 9 ++++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

Comments

Darrick J. Wong May 8, 2018, 5:32 p.m. UTC | #1
On Mon, May 07, 2018 at 09:41:17PM -0700, Allison Henderson wrote:
> Variable sized arrays implemented this way may cause
> corruptions depending on how different compilers pack
> the structure.
> 
> Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
> ---
>  include/parent.h | 1 -
>  io/parent.c      | 9 ++++++---
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/include/parent.h b/include/parent.h
> index f338f96..85cef85 100644
> --- a/include/parent.h
> +++ b/include/parent.h
> @@ -22,7 +22,6 @@ typedef struct parent {
>  	__u64	p_ino;
>  	__u32	p_gen;
>  	__u16	p_reclen;
> -	char	p_name[1];
>  } parent_t;

Two options here: Either we finally fix up this part of libhandle to
talk to the kernel ioctls (whether or not we use the new apis in the
'upper half' patch at the end of this series to provide that emulation)
or just deprecate and kill all this old parent pointer stuff since it
has never worked on Linux.

FWIW struct parent is an in-core structure exposed via libhandle so (a)
we can't change it and (b) the padding problems don't exist.

--D

>  
>  typedef struct parent_cursor {
> diff --git a/io/parent.c b/io/parent.c
> index 1968516..55b8b49 100644
> --- a/io/parent.c
> +++ b/io/parent.c
> @@ -45,7 +45,8 @@ check_parent_entry(xfs_bstat_t *bstatp, parent_t *parent)
>  	struct stat statbuf;
>  	char *str;
>  
> -	sprintf(fullpath, _("%s%s"), mntpt, parent->p_name);
> +	snprintf(fullpath, parent->p_reclen, _("%s%s"), mntpt,
> +				((char*)parent)+sizeof(struct parent));
>  
>  	sts = lstat(fullpath, &statbuf);
>  	if (sts != 0) {
> @@ -284,9 +285,11 @@ print_parent_entry(parent_t *parent, int fullpath)
>  	printf(_("p_gen    = %u\n"),	parent->p_gen);
>  	printf(_("p_reclen = %u\n"),	parent->p_reclen);
>  	if (fullpath)
> -		printf(_("p_name   = \"%s%s\"\n"), mntpt, parent->p_name);
> +		printf(_("p_name   = \"%s%s\"\n"), mntpt,
> +					((char*)parent)+sizeof(struct parent));
>  	else
> -		printf(_("p_name   = \"%s\"\n"), parent->p_name);
> +		printf(_("p_name   = \"%s\"\n"),
> +					((char*)parent)+sizeof(struct parent));
>  }
>  
>  static int
> -- 
> 2.7.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/parent.h b/include/parent.h
index f338f96..85cef85 100644
--- a/include/parent.h
+++ b/include/parent.h
@@ -22,7 +22,6 @@  typedef struct parent {
 	__u64	p_ino;
 	__u32	p_gen;
 	__u16	p_reclen;
-	char	p_name[1];
 } parent_t;
 
 typedef struct parent_cursor {
diff --git a/io/parent.c b/io/parent.c
index 1968516..55b8b49 100644
--- a/io/parent.c
+++ b/io/parent.c
@@ -45,7 +45,8 @@  check_parent_entry(xfs_bstat_t *bstatp, parent_t *parent)
 	struct stat statbuf;
 	char *str;
 
-	sprintf(fullpath, _("%s%s"), mntpt, parent->p_name);
+	snprintf(fullpath, parent->p_reclen, _("%s%s"), mntpt,
+				((char*)parent)+sizeof(struct parent));
 
 	sts = lstat(fullpath, &statbuf);
 	if (sts != 0) {
@@ -284,9 +285,11 @@  print_parent_entry(parent_t *parent, int fullpath)
 	printf(_("p_gen    = %u\n"),	parent->p_gen);
 	printf(_("p_reclen = %u\n"),	parent->p_reclen);
 	if (fullpath)
-		printf(_("p_name   = \"%s%s\"\n"), mntpt, parent->p_name);
+		printf(_("p_name   = \"%s%s\"\n"), mntpt,
+					((char*)parent)+sizeof(struct parent));
 	else
-		printf(_("p_name   = \"%s\"\n"), parent->p_name);
+		printf(_("p_name   = \"%s\"\n"),
+					((char*)parent)+sizeof(struct parent));
 }
 
 static int