Fixed reference to overlapping (the same) string. The intent of the rootdev_get_device_slave is to allow the slave and the device to be the same string but it is not required. Added a test for the case where they are the same string to not do the strncpy. Linux has vixed the problem of a limited number of stacked devices, so I fixed the comment that referred to it. BUG=chromium:259893 TEST=rootdev -s Change-Id: I04d84799e77c678f1330e1bcf72cddaf9ac68c4c Reviewed-on: https://gerrit.chromium.org/gerrit/61707 Tested-by: Paul Taysom <taysom@chromium.org> Reviewed-by: Yunlian Jiang <yunlian@chromium.org> Commit-Queue: Paul Taysom <taysom@chromium.org>
diff --git a/rootdev.c b/rootdev.c index 5ef0c3d..ee877c0 100644 --- a/rootdev.c +++ b/rootdev.c
@@ -22,9 +22,9 @@ #include <unistd.h> /* - * A depth of more than about 4 slave devices - * will run out of kernel stack space, so setting - * the serach depth to 8 covers all possible cases. + * Limit prevents endless looping to find slave. + * We currently have at most 2 levels, this allows + * for future growth. */ #define MAX_SLAVE_DEPTH 8 @@ -283,7 +283,8 @@ * and find the last device. For example, verity can be stacked on bootcache * that is stacked on a disk partition. */ - strncpy(slave, device, size); + if (slave != device) + strncpy(slave, device, size); slave[size - 1] = '\0'; for (i = 0; i < MAX_SLAVE_DEPTH; i++) { len = snprintf(dst, sizeof(dst), "%s/%s/slaves", search, slave);