Skip to content

Fix crash on non-integer value argument (#2)#3

Open
p0dalirius wants to merge 1 commit intomainfrom
bugfix-invalid-value-crash
Open

Fix crash on non-integer value argument (#2)#3
p0dalirius wants to merge 1 commit intomainfrom
bugfix-invalid-value-crash

Conversation

@p0dalirius
Copy link
Copy Markdown
Owner

Linked Issue

Closes #2

Root Cause

The value argparse argument is taken as a raw string and fed directly into int(options.value) at two sites in the __main__ block without any surrounding error handling. Any string that is not a valid base-10 integer literal (e.g. 0x220, abc) therefore raises an uncaught ValueError and the interpreter prints a traceback.

Fix Description

Move the int(options.value) conversion out of each attribute branch and into a single try block that runs immediately after parseArgs(). On ValueError the program now prints a clear [!] Invalid value ...: expected an integer message and exits with status code 1. The attribute branches keep their existing behaviour and are now reached only when the value is a valid integer.

How Verified

Runtime checks before and after the patch:

Before:

$ ./msFlagsDecoder.py userAccountControl 0x220
Traceback (most recent call last):
  ...
ValueError: invalid literal for int() with base 10: '0x220'

After:

$ ./msFlagsDecoder.py userAccountControl 0x220
[!] Invalid value '0x220': expected an integer
$ echo $?
1

$ ./msFlagsDecoder.py userAccountControl abc
[!] Invalid value 'abc': expected an integer
$ echo $?
1

$ ./msFlagsDecoder.py sAMAccountType xyz
[!] Invalid value 'xyz': expected an integer
$ echo $?
1

$ ./msFlagsDecoder.py userAccountControl 512
[>] userAccountControl value       : 0x200
  | NORMAL_ACCOUNT                 : It's a default account type that represents a typical user.

$ ./msFlagsDecoder.py sAMAccountType 805306368
[>] sAMAccountType value      : 0x30000000
  | SAM_USER_OBJECT           : Represents a user object.

Test Coverage

None: repository has no automated test suite; the fix is verified by the runtime checks above. Adding a test harness is out of scope for this bug fix.

Scope of Change

  • Files changed: msFlagsDecoder.py
  • Submodule pointer updated: no
  • Behavioral changes outside the bug fix: none

Risk and Rollout

Local change limited to the CLI entry point. The only behavioural difference for previously-accepted inputs is that the integer parse happens one step earlier, which is observationally equivalent. Safe to merge without staged rollout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught ValueError crash when value argument is not a decimal integer

1 participant