luci-base: cbi.js: fix unintended number sign overflow in format
authorJo-Philipp Wich <jo@mein.io>
Tue, 3 Sep 2019 17:25:39 +0000 (19:25 +0200)
committerJo-Philipp Wich <jo@mein.io>
Wed, 29 Jan 2020 13:41:34 +0000 (14:41 +0100)
Fixes: #3003
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(backported from commit 6d9a23af60f796e14dd9652d4f401db1a5ac456f)

modules/luci-base/htdocs/luci-static/resources/cbi.js

index 47501bd477505204e5de1f49de7351126ce4a7e4..da3f84e055c45572aa2d28d3c28068573af285a4 100644 (file)
@@ -1403,7 +1403,7 @@ String.prototype.format = function()
                                switch(pType)
                                {
                                        case 'b':
-                                               subst = (+param || 0).toString(2);
+                                               subst = Math.floor(+param || 0).toString(2);
                                                break;
 
                                        case 'c':
@@ -1411,11 +1411,12 @@ String.prototype.format = function()
                                                break;
 
                                        case 'd':
-                                               subst = ~~(+param || 0);
+                                               subst = Math.floor(+param || 0).toFixed(0);
                                                break;
 
                                        case 'u':
-                                               subst = ~~Math.abs(+param || 0);
+                                               var n = +param || 0;
+                                               subst = Math.floor((n < 0) ? 0x100000000 + n : n).toFixed(0);
                                                break;
 
                                        case 'f':
@@ -1425,7 +1426,7 @@ String.prototype.format = function()
                                                break;
 
                                        case 'o':
-                                               subst = (+param || 0).toString(8);
+                                               subst = Math.floor(+param || 0).toString(8);
                                                break;
 
                                        case 's':
@@ -1433,11 +1434,11 @@ String.prototype.format = function()
                                                break;
 
                                        case 'x':
-                                               subst = ('' + (+param || 0).toString(16)).toLowerCase();
+                                               subst = Math.floor(+param || 0).toString(16).toLowerCase();
                                                break;
 
                                        case 'X':
-                                               subst = ('' + (+param || 0).toString(16)).toUpperCase();
+                                               subst = Math.floor(+param || 0).toString(16).toUpperCase();
                                                break;
 
                                        case 'h':