Skip to content

Commit

Permalink
fix unbounded write of sprintf
Browse files Browse the repository at this point in the history
Buffer write operations that do not control the length of data written
may overflow. Fix by replacing sprintf() with snprintf().
  • Loading branch information
szsam authored and cgutman committed Mar 25, 2024
1 parent 014af67 commit 274d3db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions libgamestream/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ int http_init(const char* keyDirectory, int logLevel) {
return GS_FAILED;

char certificateFilePath[4096];
sprintf(certificateFilePath, "%s/%s", keyDirectory, CERTIFICATE_FILE_NAME);
snprintf(certificateFilePath, sizeof(certificateFilePath), "%s/%s", keyDirectory, CERTIFICATE_FILE_NAME);

char keyFilePath[4096];
sprintf(&keyFilePath[0], "%s/%s", keyDirectory, KEY_FILE_NAME);
snprintf(keyFilePath, sizeof(keyFilePath), "%s/%s", keyDirectory, KEY_FILE_NAME);

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L);
Expand Down
6 changes: 3 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) {
struct passwd *pw = getpwuid(getuid());
const char *dir;
if ((dir = getenv("XDG_CACHE_DIR")) != NULL)
sprintf(config->key_dir, "%s" MOONLIGHT_PATH, dir);
snprintf(config->key_dir, sizeof(config->key_dir), "%s" MOONLIGHT_PATH, dir);
else if ((dir = getenv("HOME")) != NULL)
sprintf(config->key_dir, "%s" DEFAULT_CACHE_DIR MOONLIGHT_PATH, dir);
snprintf(config->key_dir, sizeof(config->key_dir), "%s" DEFAULT_CACHE_DIR MOONLIGHT_PATH, dir);
else
sprintf(config->key_dir, "%s" DEFAULT_CACHE_DIR MOONLIGHT_PATH, pw->pw_dir);
snprintf(config->key_dir, sizeof(config->key_dir), "%s" DEFAULT_CACHE_DIR MOONLIGHT_PATH, pw->pw_dir);
}

if (config->stream.bitrate == -1) {
Expand Down

0 comments on commit 274d3db

Please sign in to comment.