Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion modules/win-bcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,34 @@ function restart(delay)
child.waitExit();
}

//
// Stub used on the 32-bit agent on 64-bit windows branch, where bcdedit cannot be invoked from a 32 bit process
//
function notSupported()
{
throw ('win-bcd: this function is not supported when running a 32 bit agent on 64 bit windows');
}

if (require('_GenericMarshal').PointerSize == 4 && require('os').arch() == 'x64')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🟠 win-bcd.js exports two different function sets for the two branches, breaking the caller-agnostic contract of MESHCENT-005/MESHCENT-006-2

In modules/win-bcd.js, added a notSupported() helper function that throws a descriptive error, and changed the '32-bit agent on 64-bit windows' branch's module.exports (around the if (require('_GenericMarshal').PointerSize == 4 && require('os').arch() == 'x64') block) to include getKeys, setKey, deleteKey, and getKey mapped to notSupported, plus a bootMode property (defaulting to 'NORMAL' via Object.defineProperty) so both branches now export the identical API surface. Callers destructuring any of these members will get a callable function/property on both branches instead of undefined; calling the unsupported ones throws a clear error rather than failing silently. Risk: the exact error-throwing convention (string throw vs Error object) and the bootMode fallback value were not specified anywhere in the file, so this is an inferred convention, not a verified one — a complete fix might want a different error type or to log rather than throw depending on caller expectations elsewhere in the codebase.

🤖 Prompt for AI agents
In modules/win-bcd.js around line 123, review and complete this code-review fix: win-bcd.js exports two different function sets for the two branches, breaking the caller-agnostic contract of MESHCENT-005/MESHCENT-006-2.
What the draft fix changed: In `modules/win-bcd.js`, added a `notSupported()` helper function that throws a descriptive error, and changed the '32-bit agent on 64-bit windows' branch's `module.exports` (around the `if (require('_GenericMarshal').PointerSize == 4 && require('os').arch() == 'x64')` block) to include `getKeys`, `setKey`, `deleteKey`, and `getKey` mapped to `notSupported`, plus a `bootMode` property (defaulting to `'NORMAL'` via `Object.defineProperty`) so both branches now export the identical API surface. Callers destructuring any of these members will get a callable function/property on both branches instead of `undefined`; calling the unsupported ones throws a clear error rather than failing silently. Risk: the exact error-throwing convention (string throw vs Error object) and the `bootMode` fallback value were not specified anywhere in the file, so this is an inferred convention, not a verified one — a complete fix might want a different error type or to log rather than throw depending on caller expectations elsewhere in the codebase.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟡 65 medium — react 👍/👎 to teach the reviewer

{
//
// 32 bit agent running on 64 bit windows, we do not expose BCD functions, because bcdedit does not work from a 32 bit process on 64 bit windows
// We still export the full API surface, but the unsupported functions throw a descriptive error instead of being undefined
//
module.exports =
{
getKeys: notSupported, setKey: notSupported, deleteKey: notSupported, getKey: notSupported,
enableSafeModeService: enableSafeModeService,
disableSafeModeService: disableSafeModeService, restart: restart, isSafeModeService: isSafeModeService
};

Object.defineProperty(module.exports, "bootMode",
{
get: function ()
{
return ('NORMAL');
}
});
}
else
{
Expand Down Expand Up @@ -166,4 +184,4 @@ else
}
}
});
}
}