Skip to content

Commit 088786f

Browse files
committed
Safe modifications in SetRawValue
(cherry picked from commit 2e51f2e)
1 parent 487338d commit 088786f

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

Mono.Debugging/Mono.Debugging.Evaluation/ArrayElementGroup.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@ public void SetRawValue (ObjectPath path, object value, EvaluationOptions option
329329
int[] idx = StringToIndices (path [1]);
330330

331331
EvaluationContext cctx = ctx.WithOptions (options);
332-
object val = cctx.Adapter.FromRawValue (cctx, value);
333-
array.SetElement (idx, val);
332+
ValueModificationUtil.ModifyValueFromRaw (cctx, value, val => array.SetElement (idx, val));
334333
}
335334
}
336335

Mono.Debugging/Mono.Debugging.Evaluation/ValueModificationUtil.cs

+15-5
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,25 @@ internal static EvaluationResult ModifyValue (EvaluationContext context, string
3636
throw new ValueModificationException(string.Format ("Cannot get real object of {0}", value), e);
3737
}
3838
var convertedValue = ConvertRightHandValue (context, val, expectedType);
39-
try {
40-
valueSetter (convertedValue);
41-
} catch (Exception e) {
42-
throw new ValueModificationException(string.Format ("Error while assigning new value to object: {0}", e.Message), e);
43-
}
39+
ModifyValue (convertedValue, valueSetter);
4440
// don't wrap with try-catch it, this call normally should not throw exceptions produced by wrong user input.
4541
// If exception was occured this means something has gone wrong in we have to report it in log
4642
return context.Evaluator.TargetObjectToExpression (context, convertedValue);
4743
}
4844

45+
internal static void ModifyValueFromRaw (EvaluationContext context, object rawValue, Action<object> valueSetter)
46+
{
47+
object val = context.Adapter.FromRawValue (context, rawValue);
48+
ModifyValue (val, valueSetter);
49+
}
50+
51+
static void ModifyValue (object value, Action<object> valueSetter)
52+
{
53+
try {
54+
valueSetter (value);
55+
} catch (Exception e) {
56+
throw new ValueModificationException (string.Format ("Error while assigning new value to object: {0}", e.Message), e);
57+
}
58+
}
4959
}
5060
}

Mono.Debugging/Mono.Debugging.Evaluation/ValueReference.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected virtual void SetRawValue (ObjectPath path, object value, EvaluationOpt
169169
{
170170
var ctx = GetContext (options);
171171

172-
SetValue (ctx, Context.Adapter.FromRawValue (ctx, value));
172+
ValueModificationUtil.ModifyValueFromRaw (ctx, value, val => SetValue (ctx, val));
173173
}
174174

175175
ObjectValue[] IObjectValueSource.GetChildren (ObjectPath path, int index, int count, EvaluationOptions options)

0 commit comments

Comments
 (0)