From dc55a7fc6c5e134449d1745ec07ca1273c1c2efb Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sat, 23 May 2020 13:21:34 -0400 Subject: [PATCH] Prettification, set errno on errors --- src/frame.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/frame.c b/src/frame.c index ad149a1..dbcaba9 100644 --- a/src/frame.c +++ b/src/frame.c @@ -3,7 +3,9 @@ #include -static ssize_t frame_decode_station(patty_ax25_address *address, void *data, off_t offset) { +static ssize_t frame_decode_station(patty_ax25_address *address, + void *data, + off_t offset) { int i, space = 0; uint8_t ssid = ((uint8_t *)data + offset)[6]; @@ -59,7 +61,9 @@ error: return -1; } -static ssize_t frame_decode_hops(patty_ax25_frame *frame, void *data, off_t start) { +static ssize_t frame_decode_hops(patty_ax25_frame *frame, + void *data, + off_t start) { ssize_t decoded; off_t offset = start; @@ -101,7 +105,9 @@ error: return -1; } -static ssize_t frame_decode_address(patty_ax25_frame *frame, void *data, off_t start) { +static ssize_t frame_decode_address(patty_ax25_frame *frame, + void *data, + off_t start) { off_t offset = start; ssize_t decoded; @@ -153,7 +159,9 @@ error: return -1; } -static ssize_t frame_decode_payload(patty_ax25_frame *frame, void *data, off_t offset) { +static ssize_t frame_decode_payload(patty_ax25_frame *frame, + void *data, + off_t offset) { uint8_t control = ((uint8_t *)data + offset)[0]; size_t decoded = 0; @@ -206,7 +214,7 @@ error: int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t size) { ssize_t decoded; - off_t offset = 0; + off_t offset = 0; memset(frame, '\0', sizeof(*frame)); @@ -216,16 +224,20 @@ int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t size) { * First, decode the variable-length Address field. */ if ((decoded = frame_decode_address(frame, data, offset)) < 0) { + errno = EIO; + goto error_decode; } else { offset += decoded; } /* - * Now, decode the remaining Control Field, optional Protocol Identifier + * Next, decode the remaining Control Field, optional Protocol Identifier * field, and payload that may follow. */ if ((decoded = frame_decode_payload(frame, data, offset)) < 0) { + errno = EIO; + goto error_decode; } else { offset += decoded;