linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [mdadm PATCH 2/2] Fix unterminated buffer after readlink() call
@ 2011-10-13  9:22 Thomas Jarosch
  2011-10-17  0:19 ` NeilBrown
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Jarosch @ 2011-10-13  9:22 UTC (permalink / raw)
  To: NeilBrown; +Cc: linux-raid


Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
---
 mdopen.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/mdopen.c b/mdopen.c
index 0a17421..555ab84 100644
--- a/mdopen.c
+++ b/mdopen.c
@@ -360,8 +360,12 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
 
 			if (lstat(chosen, &stb) == 0) {
 				char buf[300];
+				ssize_t link_len = readlink(chosen, buf, sizeof(buf)-1);
+				if (link_len >= 0)
+					buf[link_len] = '\0';
+
 				if ((stb.st_mode & S_IFMT) != S_IFLNK ||
-				    readlink(chosen, buf, 300) <0 ||
+				    link_len < 0 ||
 				    strcmp(buf, devname) != 0) {
 					fprintf(stderr, Name ": %s exists - ignoring\n",
 						chosen);
-- 
1.7.4.4

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

* Re: [mdadm PATCH 2/2] Fix unterminated buffer after readlink() call
  2011-10-13  9:22 [mdadm PATCH 2/2] Fix unterminated buffer after readlink() call Thomas Jarosch
@ 2011-10-17  0:19 ` NeilBrown
  0 siblings, 0 replies; 2+ messages in thread
From: NeilBrown @ 2011-10-17  0:19 UTC (permalink / raw)
  To: Thomas Jarosch; +Cc: linux-raid

[-- Attachment #1: Type: text/plain, Size: 949 bytes --]

On Thu, 13 Oct 2011 11:22:13 +0200 Thomas Jarosch
<thomas.jarosch@intra2net.com> wrote:

> 
> Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
> ---
>  mdopen.c |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/mdopen.c b/mdopen.c
> index 0a17421..555ab84 100644
> --- a/mdopen.c
> +++ b/mdopen.c
> @@ -360,8 +360,12 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
>  
>  			if (lstat(chosen, &stb) == 0) {
>  				char buf[300];
> +				ssize_t link_len = readlink(chosen, buf, sizeof(buf)-1);
> +				if (link_len >= 0)
> +					buf[link_len] = '\0';
> +
>  				if ((stb.st_mode & S_IFMT) != S_IFLNK ||
> -				    readlink(chosen, buf, 300) <0 ||
> +				    link_len < 0 ||
>  				    strcmp(buf, devname) != 0) {
>  					fprintf(stderr, Name ": %s exists - ignoring\n",
>  						chosen);


Thanks.  I've applied this and the other one.

NeilBrown


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

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

end of thread, other threads:[~2011-10-17  0:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-13  9:22 [mdadm PATCH 2/2] Fix unterminated buffer after readlink() call Thomas Jarosch
2011-10-17  0:19 ` NeilBrown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).