diff --git a/src/curl.cpp b/src/curl.cpp index 4530af7..c1d0d56 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -2142,7 +2142,7 @@ bool S3fsCurl::GetResponseCode(long& responseCode, bool from_curl_handle) const // bool S3fsCurl::RemakeHandle() { - S3FS_PRN_INFO3("Retry request. [type=%d][url=%s][path=%s]", type, url.c_str(), path.c_str()); + S3FS_PRN_INFO3("Retry request. [type=%d][url=%s][path=%s]", static_cast(type), url.c_str(), path.c_str()); if(REQTYPE::UNSET == type){ return false; @@ -2444,7 +2444,7 @@ bool S3fsCurl::RemakeHandle() break; default: - S3FS_PRN_ERR("request type is unknown(%d)", type); + S3FS_PRN_ERR("request type is unknown(%d)", static_cast(type)); return false; } if(!S3fsCurl::AddUserAgent(hCurl)){ // put User-Agent diff --git a/src/fdcache.cpp b/src/fdcache.cpp index 8b79abc..b49f999 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -218,7 +218,8 @@ bool FdManager::MakeRandomTempPath(const char* path, std::string& tmppath) { char szBuff[64]; - sprintf(szBuff, NOCACHE_PATH_PREFIX_FORM, random()); // worry for performance, but maybe don't worry. + snprintf(szBuff, sizeof(szBuff), NOCACHE_PATH_PREFIX_FORM, random()); // worry for performance, but maybe don't worry. + szBuff[sizeof(szBuff) - 1] = '\0'; // for safety tmppath = szBuff; tmppath += path ? path : ""; return true; diff --git a/src/fdcache_entity.cpp b/src/fdcache_entity.cpp index 9b4fa11..119be97 100644 --- a/src/fdcache_entity.cpp +++ b/src/fdcache_entity.cpp @@ -334,7 +334,8 @@ int FdEntity::OpenMirrorFile() // (do not care for threading, because allowed any value returned.) // char szfile[NAME_MAX + 1]; - sprintf(szfile, "%x.tmp", rand_r(&seed)); + snprintf(szfile, sizeof(szfile), "%x.tmp", rand_r(&seed)); + szfile[NAME_MAX] = '\0'; // for safety mirrorpath = bupdir + "/" + szfile; // link mirror file to cache file diff --git a/test/cr_filename.cc b/test/cr_filename.cc index c77e399..411d078 100644 --- a/test/cr_filename.cc +++ b/test/cr_filename.cc @@ -41,7 +41,8 @@ int main(int argc, const char *argv[]) int fd; char filepath[4096]; - sprintf(filepath, "%s\r", argv[1]); + snprintf(filepath, sizeof(filepath), "%s\r", argv[1]); + filepath[sizeof(filepath) - 1] = '\0'; // for safety // create empty file if(-1 == (fd = open(filepath, O_CREAT|O_RDWR, 0644))){ diff --git a/test/mknod_test.cc b/test/mknod_test.cc index f5bc240..fc7137f 100644 --- a/test/mknod_test.cc +++ b/test/mknod_test.cc @@ -73,27 +73,31 @@ bool TestMknod(const char* basepath, mode_t mode) case S_IFREG: str_mode = str_mode_reg; dev = 0; - sprintf(filepath, "%s.%s", basepath, str_ext_reg); + snprintf(filepath, sizeof(filepath), "%s.%s", basepath, str_ext_reg); + filepath[S3FS_TEST_PATH_MAX - 1] = '\0'; // for safety break; case S_IFCHR: str_mode = str_mode_chr; dev = makedev(0, 0); - sprintf(filepath, "%s.%s", basepath, str_ext_chr); + snprintf(filepath, sizeof(filepath), "%s.%s", basepath, str_ext_chr); + filepath[S3FS_TEST_PATH_MAX - 1] = '\0'; // for safety break; case S_IFBLK: str_mode = str_mode_blk; - dev = makedev((unsigned int)(259), 0); // temporary value - sprintf(filepath, "%s.%s", basepath, str_ext_blk); + dev = makedev((unsigned int)(259), 0); // temporary value + snprintf(filepath, sizeof(filepath), "%s.%s", basepath, str_ext_blk); + filepath[S3FS_TEST_PATH_MAX - 1] = '\0'; // for safety break; case S_IFIFO: str_mode = str_mode_fifo; dev = 0; - sprintf(filepath, "%s.%s", basepath, str_ext_fifo); + snprintf(filepath, sizeof(filepath), "%s.%s", basepath, str_ext_fifo); + filepath[S3FS_TEST_PATH_MAX - 1] = '\0'; // for safety break; case S_IFSOCK: str_mode = str_mode_sock; dev = 0; - snprintf(filepath, S3FS_TEST_PATH_MAX, "%s.%s", basepath, str_ext_sock); + snprintf(filepath, sizeof(filepath), "%s.%s", basepath, str_ext_sock); filepath[S3FS_TEST_PATH_MAX - 1] = '\0'; // for safety break; default: diff --git a/test/truncate_read_file.cc b/test/truncate_read_file.cc index 2959439..1995b50 100644 --- a/test/truncate_read_file.cc +++ b/test/truncate_read_file.cc @@ -58,7 +58,8 @@ int main(int argc, char *argv[]) // run sub-process for reading file(cat) char szCommand[1024]; - sprintf(szCommand, "cat %s >/dev/null 2>&1", filepath); + snprintf(szCommand, sizeof(szCommand), "cat %s >/dev/null 2>&1", filepath); + szCommand[sizeof(szCommand) - 1] = '\0'; // for safety if(0 != system(szCommand)){ fprintf(stderr, "[ERROR] Failed to run sub-process(cat).\n"); close(fd);