view rvinterf/l1filter/pktsort.c @ 1011:6d9b10633f10 default tip

etmsync Pirelli IMEI retrieval: fix poor use of printf() Bug reported by Vadim Yanitskiy <fixeria@osmocom.org>: the construct where a static-allocated string was passed to printf() without any format arguments causes newer compilers to report a security problem. Given that formatted output is not needed here, just fixed string output, change printf() to fputs(), and direct the error message to stderr while at it.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 23 May 2024 17:29:57 +0000
parents ea458ee48691
children
line wrap: on
line source

/*
 * Here we sort out incoming packets from the target relayed via rvinterf.
 */

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "pktmux.h"
#include "limits.h"
#include "localsock.h"
#include "localtypes.h"
#include "exitcodes.h"

extern u_char rvi_msg[];
extern int rvi_msg_len;
extern char **filter_list;

static
is_filter_match()
{
	char **fp;
	int len;

	for (fp = filter_list; *fp; fp++) {
		len = strlen(*fp);
		if (rvi_msg_len < len + 3)
			continue;
		if (strncmp(rvi_msg + 2, *fp, len))
			continue;
		if (rvi_msg[len+2] != ' ')
			continue;
		return 1;
	}
	return 0;
}

static void
print_l1_trace()
{
	u_char *dp, *endp;
	int c, newline;

	dp = rvi_msg + 2;
	endp = rvi_msg + rvi_msg_len;
	while (dp < endp) {
		c = *dp++;
		if (c == '\r')
			continue;
		if (c == '\n') {
			putchar(c);
			newline = 1;
			continue;
		}
		newline = 0;
		if (c & 0x80) {
			putchar('M');
			putchar('-');
			c &= 0x7F;
		}
		if (c == 0x7F) {
			putchar('^');
			putchar('?');
			continue;
		}
		if (c < 0x20) {
			putchar('^');
			c += '@';
		}
		putchar(c);
	}
	if (!newline)
		putchar('\n');
}

static void
l1_packet_rx()
{
	if (is_filter_match())
		print_l1_trace();
}

void
process_pkt_from_target()
{
	switch (rvi_msg[1]) {
	case RVT_L1_HEADER:
		l1_packet_rx();
		return;
	default:
		fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n",
			rvi_msg[1]);
		exit(ERROR_RVINTERF);
	}
}