From: notaz Date: Wed, 9 Oct 2013 23:41:45 +0000 (+0300) Subject: handle no home and buf overflow X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af7e50060fc05a2200ea7221f5658e204270c7aa;p=libpicofe.git handle no home and buf overflow --- 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__