Commit 3a41759da391b2364589c3542150630402619595

Authored by Blue Swirl
1 parent bab7944c

Use snprintf to avoid OpenBSD warning

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Showing 1 changed file with 7 additions and 5 deletions
@@ -4834,6 +4834,7 @@ static char *find_datadir(const char *argv0) @@ -4834,6 +4834,7 @@ static char *find_datadir(const char *argv0)
4834 #ifdef PATH_MAX 4834 #ifdef PATH_MAX
4835 char buf[PATH_MAX]; 4835 char buf[PATH_MAX];
4836 #endif 4836 #endif
  4837 + size_t max_len;
4837 4838
4838 #if defined(__linux__) 4839 #if defined(__linux__)
4839 { 4840 {
@@ -4868,11 +4869,12 @@ static char *find_datadir(const char *argv0) @@ -4868,11 +4869,12 @@ static char *find_datadir(const char *argv0)
4868 dir = dirname(p); 4869 dir = dirname(p);
4869 dir = dirname(dir); 4870 dir = dirname(dir);
4870 4871
4871 - res = qemu_mallocz(strlen(dir) +  
4872 - MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1);  
4873 - sprintf(res, "%s%s", dir, SHARE_SUFFIX); 4872 + max_len = strlen(dir) +
  4873 + MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1;
  4874 + res = qemu_mallocz(max_len);
  4875 + snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX);
4874 if (access(res, R_OK)) { 4876 if (access(res, R_OK)) {
4875 - sprintf(res, "%s%s", dir, BUILD_SUFFIX); 4877 + snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX);
4876 if (access(res, R_OK)) { 4878 if (access(res, R_OK)) {
4877 qemu_free(res); 4879 qemu_free(res);
4878 res = NULL; 4880 res = NULL;
@@ -4910,7 +4912,7 @@ char *qemu_find_file(int type, const char *name) @@ -4910,7 +4912,7 @@ char *qemu_find_file(int type, const char *name)
4910 } 4912 }
4911 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2; 4913 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
4912 buf = qemu_mallocz(len); 4914 buf = qemu_mallocz(len);
4913 - sprintf(buf, "%s/%s%s", data_dir, subdir, name); 4915 + snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
4914 if (access(buf, R_OK)) { 4916 if (access(buf, R_OK)) {
4915 qemu_free(buf); 4917 qemu_free(buf);
4916 return NULL; 4918 return NULL;