From 0bc5c8e85f72ce145c05fd23ae5dbbe54e975a25 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 12 Jan 2017 08:52:58 -0800 Subject: [PATCH] Spi-hdlc-adapter: Copy the spi path name before passing to `syslog()` (#1135) This commit makes a change in `spi-hdlc-adapter` to copy the passed in spi path (from the argv) in a max 64 char array before passing it to `syslog()`. This ensures `syslog()` string argument has a limited size. --- tools/spi-hdlc-adapter/spi-hdlc-adapter.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/spi-hdlc-adapter/spi-hdlc-adapter.c b/tools/spi-hdlc-adapter/spi-hdlc-adapter.c index 7fcd841b6..2dd1bf0af 100644 --- a/tools/spi-hdlc-adapter/spi-hdlc-adapter.c +++ b/tools/spi-hdlc-adapter/spi-hdlc-adapter.c @@ -1478,7 +1478,11 @@ int main(int argc, char *argv[]) { if (!setup_spi_dev(argv[0])) { - syslog(LOG_ERR, "%s: Unable to open SPI device \"%s\", %s", prog, argv[0], strerror(errno)); + char spi_path[64]; + + strncpy(spi_path, argv[0], sizeof(spi_path) - 1); + spi_path[sizeof(spi_path) - 1] = 0; + syslog(LOG_ERR, "%s: Unable to open SPI device \"%s\", %s", prog, spi_path, strerror(errno)); exit(EXIT_FAILURE); } argc--;