From af7e50060fc05a2200ea7221f5658e204270c7aa Mon Sep 17 00:00:00 2001 From: notaz Date: Thu, 10 Oct 2013 02:41:45 +0300 Subject: [PATCH] handle no home and buf overflow --- linux/plat.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/linux/plat.c b/linux/plat.c index ec381fa..660a095 100644 --- a/linux/plat.c +++ b/linux/plat.c @@ -78,17 +78,19 @@ int plat_get_skin_dir(char *dst, int len) #endif int plat_get_root_dir(char *dst, int len) { -#if defined(__GP2X__) || defined(PANDORA) - return plat_get_data_dir(dst, len); -#else - char *home = getenv("HOME"); - size_t nb = strlen(home); +#if !defined(__GP2X__) && !defined(PANDORA) + const char *home = getenv("HOME"); + int ret; - memcpy(dst, home, nb); - memcpy(dst + nb, PICO_HOME_DIR, sizeof PICO_HOME_DIR); - mkdir(dst, 0755); - return nb + sizeof(PICO_HOME_DIR) - 1; + if (home != NULL) { + ret = snprintf(dst, len, "%s%s", home, PICO_HOME_DIR); + if (ret >= len) + ret = len - 1; + mkdir(dst, 0755); + return ret; + } #endif + return plat_get_data_dir(dst, len); } #ifdef __GP2X__ -- 2.39.5