All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix possible race condition in readlink.2 example
@ 2013-07-15 16:19 Chuck Coffing
       [not found] ` <20130715161929.GA22636-sklCMb5Bxfd6qHUw6WWyqb5k8TFzwjDl@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Chuck Coffing @ 2013-07-15 16:19 UTC (permalink / raw)
  To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

Hi Michael,

I noticed that the example in the readlink.2 man pages does error
checking for a race condition that would cause the value of the symbolic
link to get larger.  However, it doesn't handle the opposite case, in
which the value gets shorter.  (The NULL terminator is always set at the
old, longer offset.)  This could cause a program to operate on
uninitialized data.

Here's a patch against 3.52:



>From 3db3021cc137937c79f95d2aa1c2820b20732c22 Mon Sep 17 00:00:00 2001
From: Chuck Coffing <clc-FrUbXkNCsVf2fBVCVOL8/A@public.gmane.org>
Date: Mon, 15 Jul 2013 10:11:15 -0600
Subject: [PATCH] Fix possible race condition in readlink.2 example

---
 man2/readlink.2 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man2/readlink.2 b/man2/readlink.2
index f4ee2cb..9633149 100644
--- a/man2/readlink.2
+++ b/man2/readlink.2
@@ -204,7 +204,7 @@ main(int argc, char *argv[])
         exit(EXIT_FAILURE);
     }
 
-    linkname[sb.st_size] = \(aq\\0\(aq;
+    linkname[r] = \(aq\\0\(aq;
 
     printf("\(aq%s\(aq points to \(aq%s\(aq\\n", argv[1], linkname);
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] Fix possible race condition in readlink.2 example
       [not found] ` <20130715161929.GA22636-sklCMb5Bxfd6qHUw6WWyqb5k8TFzwjDl@public.gmane.org>
@ 2013-07-18  0:04   ` Michael Kerrisk
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Kerrisk @ 2013-07-18  0:04 UTC (permalink / raw)
  To: Chuck Coffing
  Cc: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w, linux-man-u79uwXL29TY76Z2rM5mHXA

On 07/15/13 18:19, Chuck Coffing wrote:
> Hi Michael,
> 
> I noticed that the example in the readlink.2 man pages does error
> checking for a race condition that would cause the value of the symbolic
> link to get larger.  However, it doesn't handle the opposite case, in
> which the value gets shorter.  (The NULL terminator is always set at the
> old, longer offset.)  This could cause a program to operate on
> uninitialized data.
> 
> Here's a patch against 3.52:

Thanks, Chuck. Applied.

Cheers,

Michael



>>From 3db3021cc137937c79f95d2aa1c2820b20732c22 Mon Sep 17 00:00:00 2001
> From: Chuck Coffing <clc-FrUbXkNCsVf2fBVCVOL8/A@public.gmane.org>
> Date: Mon, 15 Jul 2013 10:11:15 -0600
> Subject: [PATCH] Fix possible race condition in readlink.2 example
> 
> ---
>  man2/readlink.2 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man2/readlink.2 b/man2/readlink.2
> index f4ee2cb..9633149 100644
> --- a/man2/readlink.2
> +++ b/man2/readlink.2
> @@ -204,7 +204,7 @@ main(int argc, char *argv[])
>          exit(EXIT_FAILURE);
>      }
>  
> -    linkname[sb.st_size] = \(aq\\0\(aq;
> +    linkname[r] = \(aq\\0\(aq;
>  
>      printf("\(aq%s\(aq points to \(aq%s\(aq\\n", argv[1], linkname);
>  
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2013-07-18  0:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-15 16:19 [PATCH] Fix possible race condition in readlink.2 example Chuck Coffing
     [not found] ` <20130715161929.GA22636-sklCMb5Bxfd6qHUw6WWyqb5k8TFzwjDl@public.gmane.org>
2013-07-18  0:04   ` Michael Kerrisk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.