summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Rosenberg <drosen@google.com>2016-07-08 14:15:14 -0700
committerAmit Pundir <amit.pundir@linaro.org>2016-07-11 12:44:27 +0530
commit841eac1df7144c7ecd70ad8ea5942f12a260e845 (patch)
tree2e86e33f00ceeaa4bb6f1c541f8dfd0df6ab59f5
parent3f01d94b5033a2fbd76e92cb48ae5db4b0e35b7d (diff)
sdcardfs: Truncate packages_gid.list on overflow
packages_gid.list was improperly returning the wrong count. Use scnprintf instead, and inform the user that the list was truncated if it is. Bug: 30013843 Change-Id: Ida2b2ef7cd86dd87300bfb4c2cdb6bfe2ee1650d Signed-off-by: Daniel Rosenberg <drosen@google.com>
-rw-r--r--fs/sdcardfs/packagelist.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/fs/sdcardfs/packagelist.c b/fs/sdcardfs/packagelist.c
index 10f0d6be718b..9c3340528eee 100644
--- a/fs/sdcardfs/packagelist.c
+++ b/fs/sdcardfs/packagelist.c
@@ -335,13 +335,20 @@ static ssize_t packages_attr_show(struct config_item *item,
struct hashtable_entry *hash_cur;
struct hlist_node *h_t;
int i;
- int count = 0;
+ int count = 0, written = 0;
+ char errormsg[] = "<truncated>\n";
+
mutex_lock(&pkgl_data_all->hashtable_lock);
- hash_for_each_safe(pkgl_data_all->package_to_appid, i, h_t, hash_cur, hlist)
- count += snprintf(page + count, PAGE_SIZE - count, "%s %d\n", (char *)hash_cur->key, hash_cur->value);
+ hash_for_each_safe(pkgl_data_all->package_to_appid, i, h_t, hash_cur, hlist) {
+ written = scnprintf(page + count, PAGE_SIZE - sizeof(errormsg) - count, "%s %d\n", (char *)hash_cur->key, hash_cur->value);
+ if (count + written == PAGE_SIZE - sizeof(errormsg)) {
+ count += scnprintf(page + count, PAGE_SIZE - count, errormsg);
+ break;
+ }
+ count += written;
+ }
mutex_unlock(&pkgl_data_all->hashtable_lock);
-
return count;
}