Compare commits

...

11 Commits

Author SHA1 Message Date
Ben Gardiner 51056e9acf
Merge 63500f8dd0 into 44e6eb45e3 2026-03-10 17:25:26 +08:00
Marc Kleine-Budde 44e6eb45e3
Merge pull request #624 from marckleinebudde/canerrsim-fix-buffer-overflow
canerrsim: main(): avoid buffer overflow: check length of interface name
2026-03-09 12:27:28 +01:00
Marc Kleine-Budde 9e444073b1 canerrsim: main(): avoid buffer overflow: check length of interface name
Closes: https://github.com/linux-can/can-utils/issues/623
2026-03-09 12:23:29 +01:00
Marc Kleine-Budde 9d4f3c82a2 canerrsim: add missing \n at end of error messages 2026-03-09 12:21:33 +01:00
Marc Kleine-Budde 7e8e247b2f canerrsim: convert from show_custom_format_and_exit() to err_exit() 2026-03-09 12:20:50 +01:00
Marc Kleine-Budde 3fe1c42bbf canerrsim: err_exit(): add support for printf style formats 2026-03-09 12:18:10 +01:00
Marc Kleine-Budde 1520ab5b98
Merge pull request #620 from marckleinebudde/mcp251xfd-fix-strchr
mcp251xfd: mcp251xfd_regmap_read(): don't assign return value of `strchr()` to `char *`
2026-03-04 11:38:43 +01:00
Marc Kleine-Budde aa902ae2af mcp251xfd: mcp251xfd_regmap_read(): don't assign return value of strchr() to `char *`
The `file_path` of `strchr(file_path, '/')` is a `const char *`. In this
case the `strchr()` in debian experimental returns a `const char *`,
leading to this error message:

```
mcp251xfd/mcp251xfd-regmap.c:75:13: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
   75 |         tmp = strchr(file_path, '/');
      |             ^
```

Fix the error by using the return value from `strchr()` directly in the
`if()`.

Link: https://github.com/linux-can/can-utils/actions/runs/22649777324/job/65679726209?pr=619
2026-03-04 11:35:38 +01:00
Marc Kleine-Budde a0b592178e
Merge pull request #621 from marckleinebudde/remove-mips
github-actions: remove mips for now

Closes: https://github.com/linux-can/can-utils/issues/611
2026-03-04 11:34:12 +01:00
Marc Kleine-Budde 4f2fdecfba github-actions: remove mips for now
It's being phased out on Ubuntu rolling release.
2026-03-04 11:30:14 +01:00
Ben Gardiner 63500f8dd0 canplayer-bisect: introduce a tool to hunt for can packets by bisecting replays of candump logs 2016-04-25 20:14:28 -07:00
4 changed files with 224 additions and 29 deletions

View File

@ -75,7 +75,6 @@ jobs:
gcc \
gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabihf \
gcc-mips-linux-gnu \
libgps-dev \
make
@ -139,13 +138,6 @@ jobs:
podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/${toolchain}.cmake -DENABLE_WERROR=ON -DENABLE_GPS=${gps} -B build-${toolchain}
podman exec -i stable cmake --build build-${toolchain}
- name: Configure & Build with mips-linux-gnu-gcc
env:
toolchain: mips-linux-gnu-gcc
run: |
podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/${toolchain}.cmake -DENABLE_WERROR=ON -B build-${toolchain}
podman exec -i stable cmake --build build-${toolchain}
- name: Configure & Build with gcc (Makefile)
env:
cc: gcc

View File

@ -25,6 +25,7 @@
#include <linux/can/error.h>
#include <linux/can/raw.h>
#include <net/if.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
@ -122,27 +123,25 @@ void show_help_and_exit()
exit(EXIT_SUCCESS);
}
void err_exit(const char *msg)
void __attribute__((format (printf, 1, 2))) err_exit(const char *format, ...)
{
printf("%s", msg);
exit(EXIT_FAILURE);
}
va_list ap;
void show_custom_format_and_exit(const char *param, const char *format)
{
char str_buf[80];
sprintf(str_buf, format, param);
err_exit(str_buf);
va_start(ap, format);
vfprintf(stdout, format, ap);
va_end(ap);
exit(EXIT_FAILURE);
}
void show_invalid_option(const char *option)
{
show_custom_format_and_exit(option, "Error: Invalid option %s\n");
err_exit("Error: Invalid option %s\n", option);
}
void show_err_and_exit(const char *err_type)
{
show_custom_format_and_exit(err_type, "Error: You can only have one %s parameter!\n");
err_exit("Error: You can only have one %s parameter!\n", err_type);
}
void show_loc_err_and_exit()
@ -176,7 +175,6 @@ int main(int argc, char *argv[])
struct ifreq ifr;
struct can_frame frame;
bool show_bits = false, location_processed = false, transceiver_processed = false, arbitration_processed = false;
char tmp_str[256];
printf("CAN Sockets Error Messages Simulator\n");
if (argc < 3)
@ -537,24 +535,25 @@ int main(int argc, char *argv[])
// create socket
if ((sock = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0)
err_exit("Error while opening socket");
err_exit("Error while opening socket\n");
// set interface name
if (strlen(argv[1]) >= IFNAMSIZ)
err_exit("Name of CAN device '%s' is too long!\n\n", argv[1]);
strcpy(ifr.ifr_name, argv[1]); // can0, vcan0...
if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0) {
sprintf(tmp_str, "Error setting CAN interface name %s", argv[1]);
err_exit(tmp_str);
}
if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0)
err_exit("Error setting CAN interface name %s\n", argv[1]);
// bind socket to the CAN interface
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
err_exit("Error in socket bind");
err_exit("Error in socket bind\n");
// Send CAN error frame
if (write(sock, &frame, sizeof(frame)) < 0)
err_exit("Error writing to socket");
err_exit("Error writing to socket\n");
else
printf("CAN error frame sent\n");

205
canplayer-bisect 100755
View File

@ -0,0 +1,205 @@
#!/bin/bash
if [ -z "${CANPLAYER}" ]; then
CANPLAYER="canplayer"
fi
die() {
echo "$*" > /dev/stderr
exit 1
}
usage() {
echo "canplayer-bisect <start|stop|clean|good|yes|bad|no|again|where|undo> <logfile> <canplayer options>"
}
is_ready() {
if [ ! -d .canplayer-bisect ]; then
usage
exit 1
fi
return 0
}
setup() {
is_ready
LOGFILE=$(cat .canplayer-bisect/logfile |head -n 1)
SAVED_LEN="$(cat .canplayer-bisect/len|tail -n 1)"
LEN="$(wc -l ${LOGFILE} | awk '{ print $1 }')"
if [ "$LEN" != "$SAVED_LEN" ]; then
die "logfile has changed size. restart"
fi
CANPLAYER_ARGS=$(cat .canplayer-bisect/args |head -n 1)
HEAD="$(cat .canplayer-bisect/head |tail -n 1)"
TAIL="$(cat .canplayer-bisect/tail |tail -n 1)"
}
back() {
HEAD="$(cat .canplayer-bisect/head |tail -n 2 |head -n1)"
TAIL="$(cat .canplayer-bisect/tail |tail -n 2 |head -n1)"
}
do_undo() {
sed -i '$ d' .canplayer-bisect/head
sed -i '$ d' .canplayer-bisect/tail
}
teardown() {
mkdir -p .canplayer-bisect
echo $LEN > .canplayer-bisect/len
echo $LOGFILE > .canplayer-bisect/logfile
echo $CANPLAYER_ARGS > .canplayer-bisect/args
echo $HEAD >> .canplayer-bisect/head
echo $TAIL >> .canplayer-bisect/tail
}
show() {
cat $LOGFILE | sed -n ${HEAD},${TAIL}p
}
play() {
#we *could* pipe directly to canplayer, but then the user can't add -l i to CANPLAYER_ARGS to hunt for packets using looped playback
the_show="$(mktemp)"
trap "rm -rf \"${the_show}\"" EXIT
show > "${the_show}"
"${CANPLAYER}" ${CANPLAYER_ARGS} -I "${the_show}"
}
do_show() {
setup
show
}
check_heads_n_tails() {
if [ $HEAD -eq $TAIL ]; then
do_stop
fi
}
do_good() {
setup
check_heads_n_tails
if [ $(( $HEAD + 1 )) -eq $TAIL ]; then
TAIL=$HEAD
else
TAIL=$(( ( $TAIL - $HEAD ) / 2 + $HEAD - 1 ))
fi
teardown
play
}
do_bad() {
setup
check_heads_n_tails
back
if [ $(( $HEAD + 1 )) -eq $TAIL ]; then
HEAD=$TAIL
else
HEAD=$(( ( $TAIL - $HEAD ) / 2 + $HEAD ))
fi
teardown
play
}
do_again() {
setup
play
}
do_start() {
do_clean
LEN="$(wc -l ${LOGFILE} | awk '{ print $1 }')"
HEAD=1
TAIL=$LEN
echo "assuming logfile contains the packets you seek... bisecting to first half"
teardown
play
}
do_where() {
setup
echo "between $HEAD and $TAIL (+$(( $TAIL - $HEAD ))) of $LOGFILE"
}
do_stop() {
setup
if [ "$COMMAND" == "no" ]; then
echo "failed to find what you were looking for"
exit 1
else
echo "the packets you seek are:"
do_where
exit 0
fi
}
do_clean() {
rm -rf .canplayer-bisect
}
if [ -z "$1" ]; then
usage
exit 1
fi
COMMAND=$1
if [ ! -d .canplayer-bisect ] && [ ! -z "$2" ] && [ ! -e "$2" ]; then
usage
exit 1
fi
LOGFILE="$2"
shift
shift
CANPLAYER_ARGS="$*"
case "$COMMAND" in
start)
do_start
;;
stop)
do_stop
;;
clean)
do_clean
;;
good|yes)
do_good
;;
bad|no)
do_bad
;;
again)
do_again
;;
where)
do_where
;;
undo)
do_undo
;;
show)
do_show
;;
esac

View File

@ -72,8 +72,7 @@ int mcp251xfd_regmap_read(struct mcp251xfd_priv *priv,
return 0;
/* maybe it's something like "spi0.0" */
tmp = strchr(file_path, '/');
if (tmp)
if (strchr(file_path, '/'))
return -ENOENT;
/* first try literally */