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

readPrelogin panic for invalid packet #64

Closed
dthaluru opened this issue Nov 2, 2022 · 1 comment
Closed

readPrelogin panic for invalid packet #64

dthaluru opened this issue Nov 2, 2022 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@dthaluru
Copy link

dthaluru commented Nov 2, 2022

Bug

readPrelogin methods reads the data from transport and does not check if the packet data is received as expected. Currently it only checks for empty response. If driver received invalid packets, the driver will run in to panic with out of index error.

The driver can get invalid packets if transport is broken/disconnected.

To fix this issue, a new check to be added if expected packet length is received

    struct_buf, err := ioutil.ReadAll(r)
if err != nil {
	return nil, err
}
...
if len(struct_buf) == 0 {
	return nil, errors.New("invalid empty PRELOGIN response, it must contain at least one byte")
}
offset := 0
results := map[uint8][]byte{}
for {
	rec_type := struct_buf[offset]
	if rec_type == preloginTERMINATOR {
		break
	}

	rec_offset := binary.BigEndian.Uint16(struct_buf[offset+1:]) // will panic if packet is invalid
	rec_len := binary.BigEndian.Uint16(struct_buf[offset+3:]) // will panic if packet is invalid
	value := struct_buf[rec_offset : rec_offset+rec_len] // will panic if packet is invalid
	results[rec_type] = value
	offset += 5
}

rec_type := struct_buf[offset]

@grrlgeek grrlgeek added the bug Something isn't working label May 3, 2023
@grrlgeek
Copy link

grrlgeek commented May 3, 2023

@shueybubbles This was merged in December; can this Issue be closed?

@grrlgeek grrlgeek added this to the Backlog milestone May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants