public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] inode02: fix "slash" array overrun
@ 2013-03-20  9:44 Jan Stancek
  2013-03-20  9:53 ` Wanlong Gao
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jan Stancek @ 2013-03-20  9:44 UTC (permalink / raw)
  To: ltp-list

Remove "slash" array and convert strcat to snprintf.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 testcases/kernel/fs/inode/inode02.c |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/fs/inode/inode02.c b/testcases/kernel/fs/inode/inode02.c
index 783edf8..54e3927 100644
--- a/testcases/kernel/fs/inode/inode02.c
+++ b/testcases/kernel/fs/inode/inode02.c
@@ -80,7 +80,6 @@ int nchild;
 FILE *list_stream = NULL;
 int list_id;
 int file_id;
-char slash[1];
 
 int increment_name(), get_next_name(), mode(), escrivez(), massmurder();
 int max_depth, max_breadth, file_length;
@@ -249,9 +248,7 @@ int tree()
 	char path_list_string[PATH_STRING_LENGTH + 10];
 	int len;
 	int status;
-
-	slash[0] = '/';
-	slash[1] = '\0';
+	int snp_ret;
 
 	/********************************/
 	/*                              */
@@ -287,9 +284,13 @@ int tree()
 	/*                                      */
 	/****************************************/
 
-	strcpy(path_list_string, path_string);
-	strcat(path_list_string, slash);
-	strcat(path_list_string, "path_list");
+	snp_ret = snprintf(path_list_string, sizeof(path_list_string),
+		"%s/path_list",	path_string);
+	if (snp_ret < 0 || snp_ret >= sizeof(path_list_string)) {
+		tst_resm(TBROK, "snprintf(path_list_string,..) returned %d",
+			snp_ret);
+		exit(-1);
+	}
 	list_id = creat(path_list_string, FILE_MODE);
 	if (list_id == -1) {
 		fprintf(temp,
@@ -411,6 +412,7 @@ int level;			/* the tree depth variable */
 	char new_string[PATH_STRING_LENGTH + 1];
 	int new_level;
 	int i, j;		/* iteration counters */
+	int snp_ret;
 
 	switch_flag = level & TRUE;
 	if (strlen(string) >= MAX_PATH_STRING_LENGTH) {
@@ -427,9 +429,13 @@ int level;			/* the tree depth variable */
 	} else if (level < max_depth) {
 		for (i = 0; i <= max_breadth; i++) {
 			get_next_name();
-			strcpy(new_string, string);
-			strcat(new_string, slash);
-			strcat(new_string, name);
+			snp_ret = snprintf(new_string, sizeof(new_string),
+				"%s/%s", string, name);
+			if (snp_ret < 0 || snp_ret >= sizeof(new_string)) {
+				tst_resm(TBROK, "snprintf(new_string,..) "
+					"returned %d", snp_ret);
+				exit(-1);
+			}
 
 			/****************************************/
 			/*                                      */
-- 
1.7.1


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v2] inode02: fix "slash" array overrun
  2013-03-20  9:44 [LTP] [PATCH v2] inode02: fix "slash" array overrun Jan Stancek
@ 2013-03-20  9:53 ` Wanlong Gao
  2013-03-20 10:20 ` Caspar Zhang
  2013-03-21  0:51 ` Wanlong Gao
  2 siblings, 0 replies; 4+ messages in thread
From: Wanlong Gao @ 2013-03-20  9:53 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

On 03/20/2013 05:44 PM, Jan Stancek wrote:
> Remove "slash" array and convert strcat to snprintf.
> 
> Signed-off-by: Jan Stancek <jstancek@redhat.com>

Reviewed-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>

> ---
>  testcases/kernel/fs/inode/inode02.c |   26 ++++++++++++++++----------
>  1 files changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/testcases/kernel/fs/inode/inode02.c b/testcases/kernel/fs/inode/inode02.c
> index 783edf8..54e3927 100644
> --- a/testcases/kernel/fs/inode/inode02.c
> +++ b/testcases/kernel/fs/inode/inode02.c
> @@ -80,7 +80,6 @@ int nchild;
>  FILE *list_stream = NULL;
>  int list_id;
>  int file_id;
> -char slash[1];
>  
>  int increment_name(), get_next_name(), mode(), escrivez(), massmurder();
>  int max_depth, max_breadth, file_length;
> @@ -249,9 +248,7 @@ int tree()
>  	char path_list_string[PATH_STRING_LENGTH + 10];
>  	int len;
>  	int status;
> -
> -	slash[0] = '/';
> -	slash[1] = '\0';
> +	int snp_ret;
>  
>  	/********************************/
>  	/*                              */
> @@ -287,9 +284,13 @@ int tree()
>  	/*                                      */
>  	/****************************************/
>  
> -	strcpy(path_list_string, path_string);
> -	strcat(path_list_string, slash);
> -	strcat(path_list_string, "path_list");
> +	snp_ret = snprintf(path_list_string, sizeof(path_list_string),
> +		"%s/path_list",	path_string);
> +	if (snp_ret < 0 || snp_ret >= sizeof(path_list_string)) {
> +		tst_resm(TBROK, "snprintf(path_list_string,..) returned %d",
> +			snp_ret);
> +		exit(-1);
> +	}
>  	list_id = creat(path_list_string, FILE_MODE);
>  	if (list_id == -1) {
>  		fprintf(temp,
> @@ -411,6 +412,7 @@ int level;			/* the tree depth variable */
>  	char new_string[PATH_STRING_LENGTH + 1];
>  	int new_level;
>  	int i, j;		/* iteration counters */
> +	int snp_ret;
>  
>  	switch_flag = level & TRUE;
>  	if (strlen(string) >= MAX_PATH_STRING_LENGTH) {
> @@ -427,9 +429,13 @@ int level;			/* the tree depth variable */
>  	} else if (level < max_depth) {
>  		for (i = 0; i <= max_breadth; i++) {
>  			get_next_name();
> -			strcpy(new_string, string);
> -			strcat(new_string, slash);
> -			strcat(new_string, name);
> +			snp_ret = snprintf(new_string, sizeof(new_string),
> +				"%s/%s", string, name);
> +			if (snp_ret < 0 || snp_ret >= sizeof(new_string)) {
> +				tst_resm(TBROK, "snprintf(new_string,..) "
> +					"returned %d", snp_ret);
> +				exit(-1);
> +			}
>  
>  			/****************************************/
>  			/*                                      */
> 


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v2] inode02: fix "slash" array overrun
  2013-03-20  9:44 [LTP] [PATCH v2] inode02: fix "slash" array overrun Jan Stancek
  2013-03-20  9:53 ` Wanlong Gao
@ 2013-03-20 10:20 ` Caspar Zhang
  2013-03-21  0:51 ` Wanlong Gao
  2 siblings, 0 replies; 4+ messages in thread
From: Caspar Zhang @ 2013-03-20 10:20 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

On 03/20/2013 05:44 PM, Jan Stancek wrote:
> Remove "slash" array and convert strcat to snprintf.
>
> Signed-off-by: Jan Stancek <jstancek@redhat.com>

Reviewed-by: Caspar Zhang <caspar@casparzhang.com>

> ---
>   testcases/kernel/fs/inode/inode02.c |   26 ++++++++++++++++----------
>   1 files changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/testcases/kernel/fs/inode/inode02.c b/testcases/kernel/fs/inode/inode02.c
> index 783edf8..54e3927 100644
> --- a/testcases/kernel/fs/inode/inode02.c
> +++ b/testcases/kernel/fs/inode/inode02.c
> @@ -80,7 +80,6 @@ int nchild;
>   FILE *list_stream = NULL;
>   int list_id;
>   int file_id;
> -char slash[1];
>
>   int increment_name(), get_next_name(), mode(), escrivez(), massmurder();
>   int max_depth, max_breadth, file_length;
> @@ -249,9 +248,7 @@ int tree()
>   	char path_list_string[PATH_STRING_LENGTH + 10];
>   	int len;
>   	int status;
> -
> -	slash[0] = '/';
> -	slash[1] = '\0';
> +	int snp_ret;
>
>   	/********************************/
>   	/*                              */
> @@ -287,9 +284,13 @@ int tree()
>   	/*                                      */
>   	/****************************************/
>
> -	strcpy(path_list_string, path_string);
> -	strcat(path_list_string, slash);
> -	strcat(path_list_string, "path_list");
> +	snp_ret = snprintf(path_list_string, sizeof(path_list_string),
> +		"%s/path_list",	path_string);
> +	if (snp_ret < 0 || snp_ret >= sizeof(path_list_string)) {
> +		tst_resm(TBROK, "snprintf(path_list_string,..) returned %d",
> +			snp_ret);
> +		exit(-1);
> +	}
>   	list_id = creat(path_list_string, FILE_MODE);
>   	if (list_id == -1) {
>   		fprintf(temp,
> @@ -411,6 +412,7 @@ int level;			/* the tree depth variable */
>   	char new_string[PATH_STRING_LENGTH + 1];
>   	int new_level;
>   	int i, j;		/* iteration counters */
> +	int snp_ret;
>
>   	switch_flag = level & TRUE;
>   	if (strlen(string) >= MAX_PATH_STRING_LENGTH) {
> @@ -427,9 +429,13 @@ int level;			/* the tree depth variable */
>   	} else if (level < max_depth) {
>   		for (i = 0; i <= max_breadth; i++) {
>   			get_next_name();
> -			strcpy(new_string, string);
> -			strcat(new_string, slash);
> -			strcat(new_string, name);
> +			snp_ret = snprintf(new_string, sizeof(new_string),
> +				"%s/%s", string, name);
> +			if (snp_ret < 0 || snp_ret >= sizeof(new_string)) {
> +				tst_resm(TBROK, "snprintf(new_string,..) "
> +					"returned %d", snp_ret);
> +				exit(-1);
> +			}
>
>   			/****************************************/
>   			/*                                      */
>


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v2] inode02: fix "slash" array overrun
  2013-03-20  9:44 [LTP] [PATCH v2] inode02: fix "slash" array overrun Jan Stancek
  2013-03-20  9:53 ` Wanlong Gao
  2013-03-20 10:20 ` Caspar Zhang
@ 2013-03-21  0:51 ` Wanlong Gao
  2 siblings, 0 replies; 4+ messages in thread
From: Wanlong Gao @ 2013-03-21  0:51 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

On 03/20/2013 05:44 PM, Jan Stancek wrote:
> Remove "slash" array and convert strcat to snprintf.
> 
> Signed-off-by: Jan Stancek <jstancek@redhat.com>


Applied, thank you.

Wanlong Gao


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-03-21  0:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-20  9:44 [LTP] [PATCH v2] inode02: fix "slash" array overrun Jan Stancek
2013-03-20  9:53 ` Wanlong Gao
2013-03-20 10:20 ` Caspar Zhang
2013-03-21  0:51 ` Wanlong Gao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox