Use heap-allocated buffer in ax25dump(8)

This commit is contained in:
XANTRONIX Development 2020-10-05 12:02:14 -04:00 committed by XANTRONIX Industrial
parent 5b59b163d2
commit a672b4e44a
4 changed files with 17 additions and 27 deletions

View file

@ -17,6 +17,8 @@
#include <patty/bin/kiss.h>
#define AX25DUMP_BUFSZ 4096
static void usage(int argc, char **argv, const char *message, ...) {
if (message != NULL) {
va_list args;
@ -41,7 +43,7 @@ int main(int argc, char **argv) {
{ NULL, 0, NULL, 0 }
};
uint8_t buf[4096];
void *buf;
ssize_t readlen;
patty_kiss_tnc_info info;
@ -118,7 +120,11 @@ int main(int argc, char **argv) {
goto error_kiss_tnc_new;
}
while ((readlen = patty_kiss_tnc_recv(raw, buf, sizeof(buf))) > 0) {
if ((buf = malloc(AX25DUMP_BUFSZ)) == NULL) {
goto error_malloc_buf;
}
while ((readlen = patty_kiss_tnc_recv(raw, buf, AX25DUMP_BUFSZ)) > 0) {
ssize_t decoded,
offset = 0;
@ -176,6 +182,8 @@ error_ax25_frame_decode_address:
}
}
free(buf);
patty_kiss_tnc_destroy(raw);
if ((st.st_mode & S_IFMT) == S_IFSOCK) {
@ -187,6 +195,9 @@ error_ax25_frame_decode_address:
return 0;
error_io:
free(buf);
error_malloc_buf:
patty_kiss_tnc_destroy(raw);
error_kiss_tnc_new:

View file

@ -315,16 +315,7 @@ int patty_ax25_aprs_is_pending(patty_ax25_aprs_is *aprs) {
}
ssize_t patty_ax25_aprs_is_flush(patty_ax25_aprs_is *aprs) {
ssize_t ret;
if (patty_ax25_aprs_is_pending(aprs)) {
aprs->stats.rx_frames++;
aprs->stats.rx_bytes += aprs->encoded;
ret = aprs->encoded;
} else {
ret = 0;
}
ssize_t ret = aprs->encoded;
aprs->state = APRS_IS_HEADER;
aprs->offset_i = aprs->readlen;
@ -445,9 +436,6 @@ ssize_t patty_ax25_aprs_is_send(patty_ax25_aprs_is *aprs,
}
}
aprs->stats.tx_frames++;
aprs->stats.tx_bytes += i;
return i;
error:

View file

@ -302,14 +302,14 @@ ssize_t patty_ax25_if_flush(patty_ax25_if *iface) {
ssize_t len = iface->driver->flush(iface->phy);
if (len > 0) {
patty_ax25_if_stats *stats = iface->driver->stats(iface->phy);
struct promisc_frame frame = {
.buf = iface->rx_buf,
.len = len,
.iface = iface
};
patty_ax25_if_stats *stats = iface->driver->stats(iface->phy);
stats->rx_frames++;
stats->rx_bytes += len;

View file

@ -332,16 +332,7 @@ int patty_kiss_tnc_pending(patty_kiss_tnc *tnc) {
}
ssize_t patty_kiss_tnc_flush(patty_kiss_tnc *tnc) {
ssize_t ret;
if (patty_kiss_tnc_pending(tnc)) {
tnc->stats.rx_frames++;
tnc->stats.rx_bytes += tnc->offset_o;
ret = tnc->offset_o;
} else {
ret = 0;
}
ssize_t ret = tnc->offset_o;
tnc->state = KISS_NONE;
tnc->command = PATTY_KISS_RETURN;