drivers: modem: quectel-bg9x: fix potential null pointer dereference

reorganize code so that null pointer check is done prior to accessing
element.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
This commit is contained in:
Jacob Siverskog 2021-02-15 20:05:44 +01:00 committed by Jukka Rissanen
parent c2339db996
commit 4b5a2b989e

View file

@ -135,7 +135,7 @@ static int on_cmd_sockread_common(int socket_fd,
struct modem_socket *sock = NULL;
struct socket_read_data *sock_data;
int ret, i;
int socket_data_length = find_len(data->rx_buf->data);
int socket_data_length;
int bytes_to_skip;
if (!len) {
@ -149,6 +149,8 @@ static int on_cmd_sockread_common(int socket_fd,
return -EINVAL;
}
socket_data_length = find_len(data->rx_buf->data);
/* No (or not enough) data available on the socket. */
bytes_to_skip = digits(socket_data_length) + 2 + 4;
if (socket_data_length <= 0) {