summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Taysom <taysom@chromium.org>2013-07-12 13:03:57 -0700
committerChromeBot <chrome-bot@google.com>2013-07-12 15:52:31 -0700
commitd4c5b8be615a84dae6ced41747246d7a038b7b88 (patch)
treef2db697b6a8ad8ed1edae077ad556cbee81b07f8
parentc9880282b115a0127c948d16f4ab3c6cadcbfcd2 (diff)
downloadplatform_external_rootdev-d4c5b8be615a84dae6ced41747246d7a038b7b88.tar.gz
platform_external_rootdev-d4c5b8be615a84dae6ced41747246d7a038b7b88.tar.bz2
platform_external_rootdev-d4c5b8be615a84dae6ced41747246d7a038b7b88.zip
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>
-rw-r--r--rootdev.c9
1 files changed, 5 insertions, 4 deletions
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 @@ void rootdev_get_device_slave(char *slave, size_t size, dev_t *dev,
* 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);