GeezerVison is showing github.com — process: fix uid/gid validation to avoid crash · nodejs/node@803fbfb
File tree
Expand file treeCollapse file tree
Open diff view settings
lib/internal/bootstrap/switches
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/bootstrap/switches/does_own_process_state.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -76,7 +76,7 @@ function wrapPosixCredentialSetters(credentials) { |
76 | 76 | function wrapIdSetter(type, method) { |
77 | 77 | return function(id) { |
78 | 78 | validateId(id, 'id'); |
79 | | - if (typeof id === 'number') id |= 0; |
| 79 | + if (typeof id === 'number') id >>>= 0; |
80 | 80 | // Result is 0 on success, 1 if credential is unknown. |
81 | 81 | const result = method(id); |
82 | 82 | if (result === 1) { |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-process-uid-gid.js +7-11Lines changed: 7 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,17 +53,13 @@ assert.throws(() => { |
53 | 53 |
|
54 | 54 | // Passing -0 shouldn't crash the process |
55 | 55 | // Refs: https://github.com/nodejs/node/issues/32750 |
56 | | -try { process.setuid(-0); } catch { |
57 | | - // Continue regardless of error. |
58 | | -} |
59 | | -try { process.seteuid(-0); } catch { |
60 | | - // Continue regardless of error. |
61 | | -} |
62 | | -try { process.setgid(-0); } catch { |
63 | | - // Continue regardless of error. |
64 | | -} |
65 | | -try { process.setegid(-0); } catch { |
66 | | - // Continue regardless of error. |
| 56 | +// And neither should values exceeding 2 ** 31 - 1. |
| 57 | +for (const id of [-0, 2 ** 31, 2 ** 32 - 1]) { |
| 58 | + for (const fn of [process.setuid, process.setuid, process.setgid, process.setegid]) { |
| 59 | + try { fn(id); } catch { |
| 60 | + // Continue regardless of error. |
| 61 | + } |
| 62 | + } |
67 | 63 | } |
68 | 64 |
|
69 | 65 | // If we're not running as super user... |
|