33import com .alibaba .fastjson2 .JSONObject ;
44import io .dongtai .iast .core .handler .hookpoint .models .policy .TaintPosition ;
55import io .dongtai .iast .core .handler .hookpoint .models .taint .range .TaintRanges ;
6+ import io .dongtai .iast .core .utils .PropertyUtils ;
67import io .dongtai .iast .core .utils .StringUtils ;
78
89import java .io .StringWriter ;
@@ -286,6 +287,7 @@ public void setCallStack(StackTraceElement callStack) {
286287 }
287288
288289 public String obj2String (Object value ) {
290+ int taintValueLength = PropertyUtils .getInstance ().getTaintValueLength ();
289291 StringBuilder sb = new StringBuilder ();
290292 if (null == value ) {
291293 return "" ;
@@ -299,27 +301,37 @@ public String obj2String(Object value) {
299301 if (taint .getClass ().isArray () && !taint .getClass ().getComponentType ().isPrimitive ()) {
300302 Object [] subTaints = (Object []) taint ;
301303 for (Object subTaint : subTaints ) {
302- sb . append ( subTaint .toString ()). append ( " " );
304+ appendWithMaxLength ( sb , subTaint .toString () + " " , taintValueLength );
303305 }
304306 } else {
305- sb . append ( taint .toString ()). append ( " " );
307+ appendWithMaxLength ( sb , taint .toString () + " " , taintValueLength );
306308 }
307309 }
308310 }
309311 } else if (value instanceof StringWriter ) {
310- sb . append ((( StringWriter ) value ).getBuffer ().toString ());
312+ appendWithMaxLength ( sb , (( StringWriter ) value ).getBuffer ().toString (), taintValueLength );
311313 } else {
312- sb . append ( value .toString ());
314+ appendWithMaxLength ( sb , value .toString (), taintValueLength );
313315 }
314316 } catch (Throwable e ) {
315317 // org.jruby.RubyBasicObject.hashCode() may cause NullPointerException when RubyBasicObject.metaClass is null
316- sb .append (value .getClass ().getName ())
317- .append ("@" )
318- .append (Integer .toHexString (System .identityHashCode (value )));
318+ String typeName = value .getClass ().getName () + "@" + Integer .toHexString (System .identityHashCode (value ));
319+ appendWithMaxLength (sb , typeName , taintValueLength );
319320 }
320321 return sb .toString ();
321322 }
322323
324+ private void appendWithMaxLength (StringBuilder sb , String content , int maxLength ) {
325+ if (sb .length () + content .length () > maxLength ) {
326+ int remainingSpace = maxLength - sb .length ();
327+ if (remainingSpace > 0 ) {
328+ sb .append (content , 0 , remainingSpace );
329+ }
330+ } else {
331+ sb .append (content );
332+ }
333+ }
334+
323335 public List <Object > getStacks () {
324336 return stacks ;
325337 }
0 commit comments