summaryrefslogtreecommitdiff
path: root/debian/patches
diff options
context:
space:
mode:
authormadduck <madduck@3cfab66f-1918-0410-86b3-c06b76f9a464>2006-09-21 13:25:53 +0000
committermadduck <madduck@3cfab66f-1918-0410-86b3-c06b76f9a464>2006-09-21 13:25:53 +0000
commita9d604a73a296ed9f596f291637bef36da260cfe (patch)
tree8e1ddc0c3fb773e6257069312a7dd11d45b16b4b /debian/patches
parentc1774279806e0bc20f352e3aaa8af8ae2704f528 (diff)
Reworked the parsing of /proc/partitions and spotted a mean segfault
(closes: #388355).
Diffstat (limited to 'debian/patches')
-rwxr-xr-xdebian/patches/50-superblock-partition-limit.dpatch61
1 files changed, 48 insertions, 13 deletions
diff --git a/debian/patches/50-superblock-partition-limit.dpatch b/debian/patches/50-superblock-partition-limit.dpatch
index eea10115..ed853138 100755
--- a/debian/patches/50-superblock-partition-limit.dpatch
+++ b/debian/patches/50-superblock-partition-limit.dpatch
@@ -6,9 +6,33 @@
@DPATCH@
diff -urNad mdadm.git~/config.c mdadm.git/config.c
---- mdadm.git~/config.c 2006-09-17 19:06:01.000000000 +0200
-+++ mdadm.git/config.c 2006-09-17 19:06:36.000000000 +0200
-@@ -222,28 +222,82 @@
+--- mdadm.git~/config.c 2006-09-20 17:44:25.892724113 +0200
++++ mdadm.git/config.c 2006-09-20 17:46:43.775794421 +0200
+@@ -219,35 +219,116 @@
+ char *name;
+ } *cdevlist = NULL;
+
++char* skipblanks(char* buf)
++{
++ if (!buf) return buf;
++ while (*buf != '\0' && isblank(*buf)) ++buf;
++ return buf;
++}
++
++char* skipnonblanks(char* buf)
++{
++ if (!buf) return buf;
++ while (*buf != '\0' && !isblank(*buf)) ++buf;
++ return buf;
++}
++
++char* skipdigits(char* buf)
++{
++ if (!buf) return buf;
++ while (*buf != '\0' && isdigit(*buf)) ++buf;
++ return buf;
++}
++
mddev_dev_t load_partitions(void)
{
FILE *f = fopen("/proc/partitions", "r");
@@ -24,7 +48,7 @@ diff -urNad mdadm.git~/config.c mdadm.git/config.c
- int major, minor;
- char *name, *mp;
+ while (!feof(f) && fgets(buf, 1024, f)) {
-+ unsigned long major, minor, iter;
++ unsigned long major, minor;
+ char *name, *kernel_name, *mp, *ptr;
mddev_dev_t d;
@@ -41,6 +65,7 @@ diff -urNad mdadm.git~/config.c mdadm.git/config.c
+ */
+ ptr = strchr(buf, '\n');
+ if (ptr) *ptr = '\0';
++ fprintf(stderr, "Line: %s\n", buf);
+
+ /*
+ * Extract the major and minor numbers and obtain the device node name.
@@ -50,8 +75,13 @@ diff -urNad mdadm.git~/config.c mdadm.git/config.c
major = strtoul(buf, &mp, 10);
- if (mp == buf || *mp != ' ')
- continue;
+- minor = strtoul(mp, NULL, 10);
+ if (mp == buf || *mp != ' ') continue;
- minor = strtoul(mp, NULL, 10);
++ mp = skipblanks(mp);
++ fprintf(stderr, "mp1='%c'\n", (unsigned char)*mp);
++ minor = strtoul(mp, &mp, 10);
++ mp = skipblanks(mp);
++ fprintf(stderr, "mp2='%c'\n", (unsigned char)*mp);
name = map_dev(major, minor, 1);
- if (!name)
@@ -59,22 +89,22 @@ diff -urNad mdadm.git~/config.c mdadm.git/config.c
+ if (!name) continue;
+
+ /*
-+ * Get the kernel name, which is the forth of the space-separated fields.
++ * mp now points at the third field, which is digits only. We thus skip
++ * all spaces and digits to reach the forth field.
+ */
-+ mp = buf;
-+ while (isspace(*(++mp)));
-+ for (iter = 0; iter < 3; ++iter) {
-+ while (!isspace(*(++mp)));
-+ while (isspace(*(++mp)));
-+ }
++ mp = skipdigits(mp);
++ fprintf(stderr, "mp3='%c'\n", (unsigned char)*mp);
++ mp = skipblanks(mp);
++ fprintf(stderr, "mp4='%c'\n", (unsigned char)*mp);
+
+ /*
+ * Now the cursor is at the beginning to the kernel name, so we point
+ * there and terminate the string on the first space character.
+ */
+ kernel_name = mp;
-+ while (!isspace(*(++mp)));
++ mp = skipnonblanks(mp);
+ *mp = '\0';
++ fprintf(stderr, "kernel_name: %s\n", kernel_name);
+
+ /*
+ * Check if this could be a partition of the previous device
@@ -102,3 +132,8 @@ diff -urNad mdadm.git~/config.c mdadm.git/config.c
d = malloc(sizeof(*d));
d->devname = strdup(name);
d->next = rv;
+ d->used = 0;
++ fprintf(stderr, "rv=%p, d=%p, d->next=%p, d->devname=%s\n", rv, d, d->next, d->devname);
+ rv = d;
+ }
+ fclose(f);