From 5429234138b1645d0c06de48c60e3c5469a81daf Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 13 Mar 2018 17:35:34 +0800 Subject: preserve non-constant value assignments with modifications (#2997) fixes #2995 --- lib/compress.js | 27 +++++++++++++++++++++++++-- test/compress/drop-unused.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 1b52f83e..cacffd37 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3114,6 +3114,8 @@ merge(Compressor.prototype, { var in_use = []; var in_use_ids = Object.create(null); // avoid expensive linear scans of in_use var fixed_ids = Object.create(null); + var value_read = Object.create(null); + var value_modified = Object.create(null); if (self instanceof AST_Toplevel && compressor.top_retain) { self.variables.each(function(def) { if (compressor.top_retain(def) && !(def.id in in_use_ids)) { @@ -3381,6 +3383,17 @@ merge(Compressor.prototype, { ); self.transform(tt); + function verify_safe_usage(def, read, modified) { + if (def.id in in_use_ids) return; + if (read && modified) { + in_use_ids[def.id] = true; + in_use.push(def); + } else { + value_read[def.id] = read; + value_modified[def.id] = modified; + } + } + function scan_ref_scoped(node, descend) { var node_def, props = [], sym = assign_as_unused(node, props); if (sym instanceof AST_SymbolRef @@ -3390,8 +3403,18 @@ merge(Compressor.prototype, { }); if (node instanceof AST_Assign) { node.right.walk(tw); - if (node.left === sym && !node_def.chained && sym.fixed_value() === node.right) { - fixed_ids[node_def.id] = node; + if (node.left === sym) { + if (!node_def.chained && sym.fixed_value() === node.right) { + fixed_ids[node_def.id] = node; + } + if (!node.write_only) { + verify_safe_usage(node_def, true, value_modified[node_def.id]); + } + } else { + var fixed = sym.fixed_value(); + if (!fixed || !fixed.is_constant()) { + verify_safe_usage(node_def, value_read[node_def.id], true); + } } } return true; diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index ee8e6c0c..301bff1c 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -1785,3 +1785,32 @@ issue_805_2: { "bar", ] } + +issue_2995: { + options = { + pure_getters: "strict", + reduce_vars: true, + unused: true, + } + input: { + function f(a) { + var b; + a.b = b = function() {}; + b.c = "PASS"; + } + var o = {}; + f(o); + console.log(o.b.c); + } + expect: { + function f(a) { + var b; + a.b = b = function() {}; + b.c = "PASS"; + } + var o = {}; + f(o); + console.log(o.b.c); + } + expect_stdout: "PASS" +} -- cgit v1.2.3 sing, given the common convention sets forth by the kernel Linux command-line parameters. * gnu/build/linux-boot.scm (boot-system): Rename '--load', '--repl', '--root' and '--system' to 'gnu.load', 'gnu.repl', 'root' and 'gnu.system', respectively. Adjust doc. (find-long-option): Adjust doc. * gnu/installer/parted.scm (installer-root-partition-path): Adjust accordingly. * gnu/system.scm (bootable-kernel-arguments): Add a VERSION argument and update doc. Use VERSION to conditionally return old style vs new style initrd arguments. (%boot-parameters-version): Increment to 1. (operating-system-boot-parameters): Adjust doc. (operating-system-boot-parameters-file): Likewise. * gnu/system/linux-initrd.scm (raw-initrd, base-initrd): Likewise. * doc/guix.texi: Adjust doc. * gnu/build/activation.scm (boot-time-system): Adjust accordingly. * gnu/build/hurd-boot.scm (boot-hurd-system): Likewise. * gnu/packages/commencement.scm (%final-inputs-riscv64): Adjust comment. Maxim Cournoyer 2021-07-29services: setuid: More configurable setuid support....New record <setuid-program> with fields for setting the specific user and group, as well as specifically selecting the setuid and setgid bits, for a program within the setuid-program-service. * gnu/services.scm (setuid-program-file-like-deprecated): New function. (setuid-program-service-type): Make use of setuid-program->activation-gexp. Adjust the extend property to handle <setuid-program>. * gnu/build/activation.scm (activate-setuid-programs): Update to expect a <setuid-record> list for each program entry. * gnu/system.scm: (operating-system-setuid-programs): Renamed to %operating-system-setuid-programs and replace it with new procedure. (operating-system-default-essential-services, hurd-default-essential-services): Replace operating-system-setuid-programs with %operating-system-setuid-programs. * gnu/system/setuid.scm: New file. * doc/guix.texi (Setuid Programs): Document <setuid-program>. Co-authored-by: Brice Waegeneire <brice@waegenei.re> Chris Lemmer-Webber 2021-04-03activation: Do not dereference symlinks during home directory creation....Fixes <https://bugs.gnu.org/47584>. * gnu/build/activation.scm (copy-account-skeletons): Do not chown the home directory; leave this to 'activate-user-home'. (activate-user-home): Only chown the home directory after the account skeletons have been copied. Co-authored-by: Ludovic Courtès <ludo@gnu.org>. Maxime Devos 2021-03-10services: Prevent following symlinks during activation....This addresses a potential security issue, where a compromised service could trick the activation code in changing the permissions, owner and group of arbitrary files. However, this patch is currently only a partial fix, due to a TOCTTOU (time-of-check to time-of-use) race, which can be fixed once guile has bindings to openat and friends. Fixes: <https://lists.gnu.org/archive/html/guix-devel/2021-01/msg00388.html> * gnu/build/activation.scm: new procedure 'mkdir-p/perms'. * gnu/services/authentication.scm (%nslcd-activation, nslcd-service-type): use new procedure. * gnu/services/cups.scm (%cups-activation): likewise. * gnu/services/dbus.scm (dbus-activation): likewise. * gnu/services/dns.scm (knot-activation): likewise. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Maxime Devos 2021-02-09activation: Do not make setuid programs setgid-root [security]....Fixes <https://bugs.gnu.org/46395>. Reported by Duncan Overbruck <mail@duncano.de>. * gnu/build/activation.scm (activate-setuid-programs): Change TARGET mode to not be setgid. Ludovic Courtès