[CRIU] [PATCH] zdtm/selfexe00: append a null byte to paths

Andrew Vagin avagin at parallels.com
Fri Nov 15 02:27:05 PST 2013


http://10.30.26.89:8080/job/Rpi-CRIU/2175/console

On Fri, Nov 15, 2013 at 02:26:32PM +0400, Andrey Vagin wrote:
> readlink() does not append a null byte to buf.
> 
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  test/zdtm/live/static/selfexe00.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/test/zdtm/live/static/selfexe00.c b/test/zdtm/live/static/selfexe00.c
> index f8fcece..a42737c 100644
> --- a/test/zdtm/live/static/selfexe00.c
> +++ b/test/zdtm/live/static/selfexe00.c
> @@ -25,25 +25,31 @@ int main(int argc, char *argv[])
>  {
>  	char path_before[PATH_MAX];
>  	char path_after[PATH_MAX];
> +	int ret;
>  
>  	test_init(argc, argv);
>  
>  	test_msg("%s pid %d\n", argv[0], getpid());
> -	if (readlink("/proc/self/exe", path_before, sizeof(path_before)) < 0) {
> +	ret = readlink("/proc/self/exe", path_before, sizeof(path_before) - 1);
> +	if (ret < 0) {
>  		err("Can't read selflink\n");
>  		fail();
>  		exit(1);
>  	}
> -
> +	path_before[ret] = 0;
> +	err("%s\n", path_before);
>  
>  	test_daemon();
>  	test_waitsig();
>  
> -	if (readlink("/proc/self/exe", path_after, sizeof(path_after)) < 0) {
> +	ret = readlink("/proc/self/exe", path_after, sizeof(path_after) - 1);
> +	if (ret < 0) {
>  		err("Can't read selflink\n");
>  		fail();
>  		exit(1);
>  	}
> +	path_after[ret] = 0;
> +	err("%s\n", path_after);
>  
>  	if (!strcmp(path_before, path_after))
>  		pass();
> -- 
> 1.8.3.1
> 


More information about the CRIU mailing list