base-files: fix uid/gid auto-enumeration to avoid 16-bit limit

uid/gid range should be limited to 16bit unsigned integer range to
avoid "wraparound" issues with permissions where jffs2
is employed for storage and chown 65536 (first auto-created user)
becomes equivalent to chown 0

Fixes: #13927

Signed-off-by: Thomas Winkler <tewinkler86@gmail.com>
(cherry picked from commit 140b48a9e9)
Link: https://github.com/openwrt/openwrt/pull/15898
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
This commit is contained in:
Thomas Winkler 2023-11-10 22:48:59 +01:00 committed by Hauke Mehrtens
parent add63dd508
commit ccac75a37f

View File

@ -371,7 +371,7 @@ group_add_next() {
return return
fi fi
gids=$(cut -d: -f3 ${IPKG_INSTROOT}/etc/group) gids=$(cut -d: -f3 ${IPKG_INSTROOT}/etc/group)
gid=65536 gid=32768
while echo "$gids" | grep -q "^$gid$"; do while echo "$gids" | grep -q "^$gid$"; do
gid=$((gid + 1)) gid=$((gid + 1))
done done
@ -402,7 +402,7 @@ user_add() {
local rc local rc
[ -z "$uid" ] && { [ -z "$uid" ] && {
uids=$(cut -d: -f3 ${IPKG_INSTROOT}/etc/passwd) uids=$(cut -d: -f3 ${IPKG_INSTROOT}/etc/passwd)
uid=65536 uid=32768
while echo "$uids" | grep -q "^$uid$"; do while echo "$uids" | grep -q "^$uid$"; do
uid=$((uid + 1)) uid=$((uid + 1))
done done