Skip to content
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

[Bug]: Possible panic: nil pointer dereference #5981

Open
ldlb9527 opened this issue Sep 13, 2024 · 2 comments
Open

[Bug]: Possible panic: nil pointer dereference #5981

ldlb9527 opened this issue Sep 13, 2024 · 2 comments
Labels

Comments

@ldlb9527
Copy link

ldlb9527 commented Sep 13, 2024

What happened?

The following code will cause a null pointer exception on the first iteration of the loop if span.TraceID has a zero value.

Steps to reproduce

https://github.com/jaegertracing/jaeger/blob/main/plugin/storage/grpc/shared/grpc_client.go#L193-L209

	var traces []*model.Trace
	var trace *model.Trace
	var traceID model.TraceID
	for received, err := stream.Recv(); !errors.Is(err, io.EOF); received, err = stream.Recv() {
		if err != nil {
			return nil, fmt.Errorf("stream error: %w", err)
		}

		for i, span := range received.Spans {
			if span.TraceID != traceID {
				trace = &model.Trace{}
				traceID = span.TraceID
				traces = append(traces, trace)
			}
			trace.Spans = append(trace.Spans, &received.Spans[i])
		}
	}
@ldlb9527 ldlb9527 added the bug label Sep 13, 2024
@ldlb9527
Copy link
Author

If this is an issue, I’m willing to create a PR to fix it.

Copy link

dosubot bot commented Sep 26, 2024

Hey there, @ldlb9527! I'm here to help you with any bugs, questions, or contributions you have. Let's work together to solve any issues you encounter.

To prevent a null pointer dereference in the Jaeger grpc_client.go code when span.TraceID has a zero value, you can add a check to ensure that span.TraceID is not zero before using it. Here is the modified code snippet from the FindTraces method:

var traces []*model.Trace
var trace *model.Trace
var traceID model.TraceID
for received, err := stream.Recv(); !errors.Is(err, io.EOF); received, err = stream.Recv() {
    if err != nil {
        return nil, fmt.Errorf("stream error: %w", err)
    }

    for i, span := range received.Spans {
        if span.TraceID.IsZero() {
            continue // Skip spans with zero TraceID
        }
        if span.TraceID != traceID {
            trace = &model.Trace{}
            traceID = span.TraceID
            traces = append(traces, trace)
        }
        trace.Spans = append(trace.Spans, &received.Spans[i])
    }
}

In this code, the span.TraceID.IsZero() method is used to check if the TraceID is zero. If it is, the span is skipped, preventing any null pointer dereference issues [1].

It looks like this issue needs your expertise, @yurishkuro, could you take a look?

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant