Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9789527f authored by Daniel Rosenberg's avatar Daniel Rosenberg Committed by Amit Pundir
Browse files

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: default avatarDaniel Rosenberg <drosen@google.com>
parent 64cd52a5
Loading
Loading
Loading
Loading
+11 −4
Original line number Original line Diff line number Diff line
@@ -349,13 +349,20 @@ static ssize_t packages_attr_show(struct config_item *item,
	struct hashtable_entry *hash_cur;
	struct hashtable_entry *hash_cur;
	struct hlist_node *h_t;
	struct hlist_node *h_t;
	int i;
	int i;
	int count = 0;
	int count = 0, written = 0;
	char errormsg[] = "<truncated>\n";

	mutex_lock(&pkgl_data_all->hashtable_lock);
	mutex_lock(&pkgl_data_all->hashtable_lock);
	hash_for_each_safe(pkgl_data_all->package_to_appid, i, h_t, hash_cur, hlist)
	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);
		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);
	mutex_unlock(&pkgl_data_all->hashtable_lock);



	return count;
	return count;
}
}