mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 15:22:20 +02:00
at: break before overflow when receiving messages
Previously this code checked if the buffer was full after writing to it, which meant that the buffer could overflow. This checks for an overflow before copying into the buffer and only copies the data that will fit.
This commit is contained in:
7
src/at.c
7
src/at.c
@@ -245,7 +245,14 @@ static gboolean modem_response(gint fd,
|
|||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
ret = read(fd, tmp, sizeof(tmp));
|
ret = read(fd, tmp, sizeof(tmp));
|
||||||
|
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
|
/* If we're going to overflow truncate the data we read to fit */
|
||||||
|
if (pos + ret >= sizeof(response)) {
|
||||||
|
g_critical("AT response buffer full, truncating");
|
||||||
|
ret = sizeof(response) - (pos + 1);
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(&response[pos], tmp, ret);
|
memcpy(&response[pos], tmp, ret);
|
||||||
pos += ret;
|
pos += ret;
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
|
Reference in New Issue
Block a user