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>
Tue, 10 Sep 2019 13:28:16 +0000 (15:28 +0200)
Fixes: #3003
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/cbi.js

index d4d61eb381119b18dc5761fe50776497a74e11a6..a3528fcaceab3796be12b9cdb6f8f01ba79fa942 100644 (file)
@@ -566,7 +566,7 @@ String.prototype.format = function()
 
                                switch(pType) {
                                        case 'b':
-                                               subst = (~~param || 0).toString(2);
+                                               subst = Math.floor(+param || 0).toString(2);
                                                break;
 
                                        case 'c':
@@ -574,11 +574,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':
@@ -588,7 +589,7 @@ String.prototype.format = function()
                                                break;
 
                                        case 'o':
-                                               subst = (~~param || 0).toString(8);
+                                               subst = Math.floor(+param || 0).toString(8);
                                                break;
 
                                        case 's':
@@ -596,11 +597,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':