tty: prefer zalloc to malloc for inverted_path allocation

Submitted by Cyrill Gorcunov on June 23, 2016, 11:16 a.m.

Details

Message ID 20160623111625.GJ2045@uranus.lan
State Accepted
Series "tty: prefer zalloc to malloc for inverted_path allocation"
Commit ead55db7d3b0d60015a561eb3fe572d67346693c
Headers show

Commit Message

Cyrill Gorcunov June 23, 2016, 11:16 a.m.
On Thu, Jun 23, 2016 at 02:12:16PM +0300, Cyrill Gorcunov wrote:
> On Thu, Jun 23, 2016 at 02:00:12PM +0300, Dmitry Safonov wrote:
> > Otherwise, we copy original name to slash and after it there may stay
> > some junk, which strcat will use for concatenation:
> > (00.024843)     26: Error (files-reg.c:1528): Can't open file dev/pts/g:��ptmx on restore: No such file or directory
> > (00.024846)     26: Error (files-reg.c:1470): Can't open file dev/pts/g:��ptmx: No such file or directory
> > (00.024849)     26: Error (tty.c:545): tty: Can't open dev/pts/g:��ptmx: No such file or directory
> > 
> > Cc: Cyrill Gorcunov <gorcunov@openvz.org>
> > Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
> 
> That's big hammer, won't the below oneliner fix it?

Give attached a shot please.
----
From: Cyrill Gorcunov <gorcunov@virtuozzo.com>
Date: Thu, 23 Jun 2016 14:14:44 +0300
Subject: [PATCH] tty: Don't forget to add eol when inverting slave pts paths

Otherwise next strcat get confused

 | (00.024843)     26: Error (files-reg.c:1528): Can't open file dev/pts/g:��^?ptmx on restore: No such file or directory
 | (00.024846)     26: Error (files-reg.c:1470): Can't open file dev/pts/g:��^?ptmx: No such file or directory
 | (00.024849)     26: Error (tty.c:545): tty: Can't open dev/pts/g:��^?ptmx: No such file or directory

Reported-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>
---
 criu/tty.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/tty.c b/criu/tty.c
index 328fafe..8b36261 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -476,9 +476,10 @@  static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int subty
 		BUG_ON(!pos || !inverted_path);
 
 		memcpy(inverted_path, orig->rfe->name, slash_at + 1);
-		if (subtype == TTY_SUBTYPE_MASTER)
+		if (subtype == TTY_SUBTYPE_MASTER) {
+			inverted_path[slash_at + 1] = '\0';
 			strcat(inverted_path, "ptmx");
-		else {
+		} else {
 			if (slash_at >= 3 && strncmp(&inverted_path[slash_at - 3], "pts", 3))
 				snprintf(&inverted_path[slash_at + 1], 10, "pts/%u",
 					 info->tie->pty->index);

Comments

Dmitry Safonov June 23, 2016, 11:28 a.m.
On 06/23/2016 02:16 PM, Cyrill Gorcunov wrote:
> On Thu, Jun 23, 2016 at 02:12:16PM +0300, Cyrill Gorcunov wrote:
>> On Thu, Jun 23, 2016 at 02:00:12PM +0300, Dmitry Safonov wrote:
>>> Otherwise, we copy original name to slash and after it there may stay
>>> some junk, which strcat will use for concatenation:
>>> (00.024843)     26: Error (files-reg.c:1528): Can't open file dev/pts/g:��ptmx on restore: No such file or directory
>>> (00.024846)     26: Error (files-reg.c:1470): Can't open file dev/pts/g:��ptmx: No such file or directory
>>> (00.024849)     26: Error (tty.c:545): tty: Can't open dev/pts/g:��ptmx: No such file or directory
>>>
>>> Cc: Cyrill Gorcunov <gorcunov@openvz.org>
>>> Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
>>
>> That's big hammer, won't the below oneliner fix it?
>
> Give attached a shot please.
> ----
> From: Cyrill Gorcunov <gorcunov@virtuozzo.com>
> Date: Thu, 23 Jun 2016 14:14:44 +0300
> Subject: [PATCH] tty: Don't forget to add eol when inverting slave pts paths
>
> Otherwise next strcat get confused
>
>  | (00.024843)     26: Error (files-reg.c:1528): Can't open file dev/pts/g:��^?ptmx on restore: No such file or directory
>  | (00.024846)     26: Error (files-reg.c:1470): Can't open file dev/pts/g:��^?ptmx: No such file or directory
>  | (00.024849)     26: Error (tty.c:545): tty: Can't open dev/pts/g:��^?ptmx: No such file or directory
>
> Reported-by: Dmitry Safonov <dsafonov@virtuozzo.com>
> Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>

All is good on the same test,
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Tested-by: Dmitry Safonov <dsafonov@virtuozzo.com>

> ---
>  criu/tty.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/criu/tty.c b/criu/tty.c
> index 328fafe..8b36261 100644
> --- a/criu/tty.c
> +++ b/criu/tty.c
> @@ -476,9 +476,10 @@ static struct reg_file_info *pty_alloc_fake_reg(struct tty_info *info, int subty
>  		BUG_ON(!pos || !inverted_path);
>
>  		memcpy(inverted_path, orig->rfe->name, slash_at + 1);
> -		if (subtype == TTY_SUBTYPE_MASTER)
> +		if (subtype == TTY_SUBTYPE_MASTER) {
> +			inverted_path[slash_at + 1] = '\0';
>  			strcat(inverted_path, "ptmx");
> -		else {
> +		} else {
>  			if (slash_at >= 3 && strncmp(&inverted_path[slash_at - 3], "pts", 3))
>  				snprintf(&inverted_path[slash_at + 1], 10, "pts/%u",
>  					 info->tie->pty->index);
>
Cyrill Gorcunov June 23, 2016, 11:32 a.m.
On Thu, Jun 23, 2016 at 02:28:44PM +0300, Dmitry Safonov wrote:
> 
> All is good on the same test,
> Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
> Tested-by: Dmitry Safonov <dsafonov@virtuozzo.com>

Thanks a lot!
Pavel Emelianov June 28, 2016, 12:39 p.m.
Applied.

When sending a patch in reply, don't leave the "Re: $original_subject"
in the Subject. Mark the reply with brand new "[PATCH] $new_description"
one. Please.

-- Pavel
Cyrill Gorcunov June 28, 2016, 12:52 p.m.
On Tue, Jun 28, 2016 at 03:39:32PM +0300, Pavel Emelyanov wrote:
> Applied.
> 
> When sending a patch in reply, don't leave the "Re: $original_subject"
> in the Subject. Mark the reply with brand new "[PATCH] $new_description"
> one. Please.

Sure. Sorry.