]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Detail.c
Grow: fix resize of array component size to > 32bits
[thirdparty/mdadm.git] / Detail.c
index 05e645c1adfed5462b9d567ee5496af46fed8597..c4fcad9620ba30aa2db22251dc9a9a5a6af1c29c 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -1,7 +1,7 @@
 /*
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2001-2012 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2001-2013 Neil Brown <neilb@suse.de>
  *
  *
  *    This program is free software; you can redistribute it and/or modify
@@ -32,6 +32,22 @@ static int cmpstringp(const void *p1, const void *p2)
        return strcmp(* (char * const *) p1, * (char * const *) p2);
 }
 
+static int add_device(const char *dev, char ***p_devices,
+                     int *p_max_devices, int n_devices)
+{
+       if (n_devices + 1 >= *p_max_devices) {
+               *p_max_devices += 16;
+               *p_devices = xrealloc(*p_devices, *p_max_devices *
+                                     sizeof(**p_devices));
+               if (!*p_devices) {
+                       *p_max_devices = 0;
+                       return 0;
+               }
+       };
+       (*p_devices)[n_devices] = xstrdup(dev);
+       return n_devices + 1;
+}
+
 int Detail(char *dev, struct context *c)
 {
        /*
@@ -93,7 +109,7 @@ int Detail(char *dev, struct context *c)
        st = super_by_fd(fd, &subarray);
        if (ioctl(fd, GET_ARRAY_INFO, &array) == 0) {
                inactive = 0;
-       } else if (errno == ENODEV) {
+       } else if (errno == ENODEV && sra) {
                array = sra->array;
                inactive = 1;
        } else {
@@ -449,8 +465,8 @@ int Detail(char *dev, struct context *c)
                               (!e || (e->percent < 0 && e->percent != RESYNC_PENDING &&
                               e->percent != RESYNC_DELAYED)) ? "" : sync_action[e->resync],
                               larray_size ? "": ", Not Started",
-                              e->percent == RESYNC_DELAYED ? " (DELAYED)": "",
-                              e->percent == RESYNC_PENDING ? " (PENDING)": "");
+                              (e && e->percent == RESYNC_DELAYED) ? " (DELAYED)": "",
+                              (e && e->percent == RESYNC_PENDING) ? " (PENDING)": "");
                } else if (inactive) {
                        printf("          State : inactive\n");
                }
@@ -660,17 +676,11 @@ This is pretty boring
                        rv |= 1;
                dv=map_dev_preferred(disk.major, disk.minor, 0, c->prefer);
                if (dv != NULL) {
-                       if (c->brief) {
-                               if (n_devices + 1 >= max_devices) {
-                                       max_devices += 16;
-                                       devices = xrealloc(devices, max_devices
-                                                          *sizeof(*devices));
-                                       if (!devices)
-                                               goto out;
-                               };
-                               devices[n_devices] = xstrdup(dv);
-                               n_devices++;
-                       } else
+                       if (c->brief)
+                               n_devices = add_device(dv, &devices,
+                                                      &max_devices,
+                                                      n_devices);
+                       else
                                printf("   %s", dv);
                }
                if (!c->brief) printf("\n");