-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add REGO debugger to Mindev. #5229
base: main
Are you sure you want to change the base?
Conversation
if err != nil { | ||
return debug.BreakpointID(-1), fmt.Errorf(`%w: invalid breakpoint id %s`, errInvalidBP, num) | ||
} | ||
return debug.BreakpointID(i), nil |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 5 days ago
To fix the problem, we need to ensure that the parsed integer is within the valid range for debug.BreakpointID
before performing the conversion. This can be done by adding an upper bound check after parsing the integer. If the parsed integer exceeds the maximum value for debug.BreakpointID
, we should return an error.
- Add an upper bound check after parsing the integer.
- Ensure that the parsed integer is within the valid range for
debug.BreakpointID
. - Return an error if the parsed integer is out of bounds.
-
Copy modified line R566 -
Copy modified line R568
@@ -565,5 +565,5 @@ | ||
|
||
if i < 1 { | ||
if i < 1 || i > math.MaxInt32 { | ||
return debug.BreakpointID(-1), fmt.Errorf( | ||
"%w: negative line id", | ||
"%w: invalid line id", | ||
errInvalidBP, |
03a9952
to
2fd436e
Compare
if err != nil { | ||
return nil, fmt.Errorf(`%w: invalid line "%s": %s`, errInvalidBP, num, err) | ||
} | ||
if i < 1 || int(i) > lineCount { |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 5 days ago
To fix the problem, we need to ensure that the value parsed by strconv.ParseInt
fits within the range of the int
type before converting it. This can be done by adding an upper bound check against math.MaxInt
(the maximum value for the int
type). If the value exceeds this limit, we should return an error.
-
Copy modified line R537 -
Copy modified line R566 -
Copy modified line R568
@@ -536,3 +536,3 @@ | ||
} | ||
if i < 1 || int(i) > lineCount { | ||
if i < 1 || i > math.MaxInt || int(i) > lineCount { | ||
return nil, fmt.Errorf("%w: invalid line %d", errInvalidBP, i) | ||
@@ -565,5 +565,5 @@ | ||
|
||
if i < 1 { | ||
if i < 1 || i > math.MaxInt { | ||
return debug.BreakpointID(-1), fmt.Errorf( | ||
"%w: negative line id", | ||
"%w: invalid line id", | ||
errInvalidBP, |
if i < 1 || int(i) > lineCount { | ||
return nil, fmt.Errorf("%w: invalid line %d", errInvalidBP, i) | ||
} | ||
return &location.Location{File: "minder.rego", Row: int(i)}, nil |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 5 days ago
To fix the problem, we need to ensure that the parsed integer value fits within the bounds of an int
before performing the conversion. This can be done by adding an upper bound check against the maximum value of an int
type. We will use the math.MaxInt
constant to perform this check.
-
Copy modified line R537
@@ -536,3 +536,3 @@ | ||
} | ||
if i < 1 || int(i) > lineCount { | ||
if i < 1 || i > int64(lineCount) || i > math.MaxInt { | ||
return nil, fmt.Errorf("%w: invalid line %d", errInvalidBP, i) |
) | ||
} | ||
|
||
if !slices.Contains(ids, debug.BreakpointID(i)) { |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 5 days ago
To fix the problem, we need to ensure that the parsed integer value falls within the valid range for the debug.BreakpointID
type before performing the conversion. This can be achieved by adding an upper bound check using the maximum value for the debug.BreakpointID
type.
- Use
strconv.ParseInt
with a bit size of 32 to directly parse the string into a 32-bit integer ifdebug.BreakpointID
is a 32-bit type. - Alternatively, add explicit bounds checks to ensure the parsed value is within the valid range for
debug.BreakpointID
.
-
Copy modified line R558 -
Copy modified line R566 -
Copy modified line R568
@@ -557,3 +557,3 @@ | ||
|
||
i, err := strconv.ParseInt(num, 10, 64) | ||
i, err := strconv.ParseInt(num, 10, 32) | ||
if err != nil { | ||
@@ -565,5 +565,5 @@ | ||
|
||
if i < 1 { | ||
if i < 1 || i > math.MaxInt32 { | ||
return debug.BreakpointID(-1), fmt.Errorf( | ||
"%w: negative line id", | ||
"%w: invalid line id", | ||
errInvalidBP, |
ef3e360
to
4edfdb7
Compare
This change adds the possibility to start evaluate a REGO-based rule type in a debugger. The debugger allows setting breakpoints, stepping, printing source, and a few other simple utilities. The debugger is currently very, very, VERY rough around the edges and could use some love, especially in the reception of events from the debuggee, which is done inline and not asynchronously.
5e66be4
to
3515312
Compare
3515312
to
586947b
Compare
Summary
This change adds the possibility to start evaluate a REGO-based rule type in a debugger.
The debugger allows setting breakpoints, stepping, printing source, and a few other simple utilities.
The debugger is currently very, very, VERY rough around the edges and could use some love, especially in the reception of events from the debuggee, which is done inline and not asynchronously.
Change Type
Testing
Mostly untested, hic sunt dracones.
Review Checklist: