]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: Specify enough length when write to buffer
authorXiao Ni <xni@redhat.com>
Fri, 17 Mar 2017 11:55:43 +0000 (19:55 +0800)
committerJes Sorensen <Jes.Sorensen@gmail.com>
Fri, 17 Mar 2017 19:58:16 +0000 (15:58 -0400)
In Detail.c the buffer path in function Detail is defined as path[200],
in fact the max lenth of content which needs to write to the buffer is
287. Because the length of dname of struct dirent is 255.
During building it reports error:
error: ā€˜%sā€™ directive writing up to 255 bytes into a region of size 189
[-Werror=format-overflow=]

In function examine_super0 there is a buffer nb with length 5.
But it need to show a int type argument. The lenght of max
number of int is 10. So the buffer length should be 11.

In human_size function the length of buf is 30. During building
there is a error:
output between 20 and 47 bytes into a destination of size 30.
Change the length to 47.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
Detail.c
super0.c
util.c

index 509b0d41876843b7c3d96be965526867c7b66aae..cb337947ac56392faa2396dc5b285361ab9fa211 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -575,7 +575,7 @@ This is pretty boring
                        printf("  Member Arrays :");
 
                        while (dir && (de = readdir(dir)) != NULL) {
-                               char path[200];
+                               char path[287];
                                char vbuf[1024];
                                int nlen = strlen(sra->sys_name);
                                dev_t devid;
index 938cfd95fa25ed2fb76f723bd1b18251df95b110..f5b4507b996c0b670a5f6b7a807cf6c872cbf5a2 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -231,7 +231,7 @@ static void examine_super0(struct supertype *st, char *homehost)
             d++) {
                mdp_disk_t *dp;
                char *dv;
-               char nb[5];
+               char nb[11];
                int wonly, failfast;
                if (d>=0) dp = &sb->disks[d];
                else dp = &sb->this_disk;
diff --git a/util.c b/util.c
index f1009723ed04c0422084d1b7c97bc3ba4d2b4d7e..32bd909b241d8295e0a7417fc0503618703c90b7 100644 (file)
--- a/util.c
+++ b/util.c
@@ -811,7 +811,7 @@ unsigned long calc_csum(void *super, int bytes)
 #ifndef MDASSEMBLE
 char *human_size(long long bytes)
 {
-       static char buf[30];
+       static char buf[47];
 
        /* We convert bytes to either centi-M{ega,ibi}bytes or
         * centi-G{igi,ibi}bytes, with appropriate rounding,