diff --git a/drivers/tilib_api.c b/drivers/tilib_api.c index 4e12465..c409981 100644 --- a/drivers/tilib_api.c +++ b/drivers/tilib_api.c @@ -16,9 +16,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include -#include #include #include "util/output.h" #include "tilib_api.h" @@ -761,15 +761,19 @@ static int init_old_api(void) int tilib_api_init(void) { int ret; - char *path, *libpath; + char libpath[PATH_MAX], *path; - if ((path = getenv("MSP430_PATH")) == NULL) - asprintf(&libpath, "%s", tilib_filename); - else - asprintf(&libpath, "%s/%s", path, tilib_filename); + libpath[0] = '\0'; + if ((path = getenv("MSP430_PATH")) != NULL) { + if (strlen(path) + strlen(tilib_filename) + 2 < PATH_MAX) { + strcat(libpath, path); + strcat(libpath, "/"); + } else + printc_err("Contents of MSP430_PATH variable are too long, ignoring\n"); + } + strcat(libpath, tilib_filename); lib_handle = dynload_open(libpath); - free(libpath); if (!lib_handle) { printc_err("tilib_api: can't find %s: %s\n",