From 3f932ac95270ed6fc7df19f59af4740c0794343e Mon Sep 17 00:00:00 2001 From: Alex Tereschenko Date: Sat, 24 Jun 2017 11:22:28 +0200 Subject: [PATCH] x86.c: sanitize data read from sysfs during board detection Fixes #771. Signed-off-by: Alex Tereschenko Signed-off-by: Brendan Le Foll --- src/x86/x86.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/x86/x86.c b/src/x86/x86.c index 1cc3dcd..ee2ac1d 100644 --- a/src/x86/x86.c +++ b/src/x86/x86.c @@ -51,6 +51,9 @@ mraa_x86_platform() FILE* fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r"); if (fh != NULL) { if (getline(&line, &len, fh) != -1) { + // Sanitize input by terminating at any of possible end of line chars + line[strcspn(line, "\r\n")] = 0; + if (strncmp(line, "GalileoGen2", strlen("GalileoGen2") + 1) == 0 || strncmp(line, "SIMATIC IOT2000", strlen("SIMATIC IOT2000") + 1) == 0) { platform_type = MRAA_INTEL_GALILEO_GEN2;