Private
Public Access
2
0

mraa.c: simplify mraa_get_platform_name with subplatforms

This removes the chance of buffer overflow with a subplatform

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2015-09-18 11:52:49 +01:00
parent 434f454139
commit 32aa4310c8

View File

@@ -408,11 +408,12 @@ mraa_get_platform_name()
if (plat == NULL) {
return NULL;
}
strncpy(platform_name, plat->platform_name, MAX_PLATFORM_NAME_LENGTH);
if (mraa_has_sub_platform()) {
strncat(platform_name, " + ", MAX_PLATFORM_NAME_LENGTH);
strncat(platform_name, plat->sub_platform->platform_name, MAX_PLATFORM_NAME_LENGTH);
snprintf(platform_name, MAX_PLATFORM_NAME_LENGTH, "%s + %s", plat->platform_name, plat->sub_platform->platform_name);
} else {
strncpy(platform_name, plat->platform_name, MAX_PLATFORM_NAME_LENGTH);
}
return platform_name;
}