From 3479ba2dba23b745092ee662296a125835fe62dc Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Sun, 8 Nov 2015 17:40:25 -0200 Subject: [PATCH 1/2] url-encode user-provided data --- cheevos.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/cheevos.c b/cheevos.c index d0572a6eab..d45a7ea5f1 100644 --- a/cheevos.c +++ b/cheevos.c @@ -1139,10 +1139,43 @@ static int cheevos_test_cheevo(cheevo_t *cheevo) return ret_val && ret_val_sub_cond; } +static void cheevos_url_encode(const char *str, char *encoded, size_t len) +{ + while (*str) + { + if (isalnum(*str) || *str == '-' || *str == '_' || *str == '.' || *str == '~') + { + if (len >= 2) + { + *encoded++ = *str++; + len--; + } + else + break; + } + else + { + if (len >= 4) + { + sprintf(encoded, "%%%02x", (uint8_t)*str); + encoded += 3; + str++; + len -= 3; + } + else + break; + } + } + + *encoded = 0; +} + static int cheevos_login(retro_time_t *timeout) { const char *username; const char *password; + char urle_user[64]; + char urle_pwd[64]; char request[256]; const char *json; int res; @@ -1161,13 +1194,16 @@ static int cheevos_login(retro_time_t *timeout) RARCH_LOG("CHEEVOS username and/or password not informed\n"); return -1; } - + + cheevos_url_encode(username, urle_user, sizeof(urle_user)); + cheevos_url_encode(password, urle_pwd, sizeof(urle_pwd)); + snprintf( request, sizeof(request), "http://retroachievements.org/dorequest.php?r=login&u=%s&p=%s", - username, password + urle_user, urle_pwd ); - + request[sizeof(request) - 1] = 0; if (!cheevos_http_get(&json, NULL, request, timeout)) From 4efb9eb6459757d2f407bc7a5c2f2aad46eba410 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Sun, 8 Nov 2015 18:47:05 -0200 Subject: [PATCH 2/2] flush the log file at every output --- libretro-common/include/retro_log.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libretro-common/include/retro_log.h b/libretro-common/include/retro_log.h index c1b156f9a6..57d2f62aa6 100644 --- a/libretro-common/include/retro_log.h +++ b/libretro-common/include/retro_log.h @@ -217,7 +217,8 @@ static INLINE void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap) __android_log_vprint(prio, PROGRAM_NAME, fmt, ap); #else fprintf(LOG_FILE, "%s %s :: ", PROGRAM_NAME, tag ? tag : "[INFO]"); - vfprintf(LOG_FILE, fmt, ap); + vfprintf(LOG_FILE, fmt, ap); + fflush(LOG_FILE); #endif }