luci-base: cbi.js: fix sfh() signedness bug for strings with 3 trailing bytes
authorJo-Philipp Wich <jo@mein.io>
Mon, 19 Nov 2018 10:58:17 +0000 (11:58 +0100)
committerJo-Philipp Wich <jo@mein.io>
Mon, 19 Nov 2018 10:58:17 +0000 (11:58 +0100)
Replace a sign-propagating right shift by a zero-filling right shift to avoid
calculating a wrong hash code in the three-trailing-bytes case.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/cbi.js

index 6cd799b92222881bc0d63153c327dc604cbd597c..0e959068129a540496c641b99dc24393b7c41470 100644 (file)
@@ -60,7 +60,7 @@ function sfh(s) {
                hash += ((bytes[off + 1] << 8) + bytes[off]) >>> 0;
                hash  = (hash ^ (hash << 16)) >>> 0;
                hash  = (hash ^ (bytes[off + 2] << 18)) >>> 0;
-               hash += hash >> 11;
+               hash += hash >>> 11;
                break;
 
        case 2: