Fixed potential atomic violation in S3fsCurl::AddUserAgent - #633

This commit is contained in:
Takeshi Nakatani 2017-09-17 09:16:05 +00:00
parent 5653ab39fc
commit 00bc9142c4
3 changed files with 20 additions and 14 deletions

View File

@ -363,6 +363,7 @@ curltime_t S3fsCurl::curl_times;
curlprogress_t S3fsCurl::curl_progress;
string S3fsCurl::curl_ca_bundle;
mimes_t S3fsCurl::mimeTypes;
string S3fsCurl::userAgent;
int S3fsCurl::max_parallel_cnt = 5; // default
off_t S3fsCurl::multipart_size = MULTIPART_SIZE; // default
bool S3fsCurl::is_sigv4 = true; // default
@ -614,6 +615,19 @@ bool S3fsCurl::InitMimeType(const char* MimeFile)
return true;
}
void S3fsCurl::InitUserAgent(void)
{
if(S3fsCurl::userAgent.empty()){
S3fsCurl::userAgent = "s3fs/";
S3fsCurl::userAgent += VERSION;
S3fsCurl::userAgent += " (commit hash ";
S3fsCurl::userAgent += COMMIT_HASH_VAL;
S3fsCurl::userAgent += "; ";
S3fsCurl::userAgent += s3fs_crypt_lib_name();
S3fsCurl::userAgent += ")";
}
}
//
// @param s e.g., "index.html"
// @return e.g., "text/html"
@ -1480,20 +1494,7 @@ bool S3fsCurl::AddUserAgent(CURL* hCurl)
return false;
}
if(S3fsCurl::IsUserAgentFlag()){
static string strua;
static bool init = false;
if(!init){
strua = "s3fs/";
strua += VERSION;
strua += " (commit hash ";
strua += COMMIT_HASH_VAL;
strua += "; ";
strua += s3fs_crypt_lib_name();
strua += ")";
init = true;
}
curl_easy_setopt(hCurl, CURLOPT_USERAGENT, strua.c_str());
curl_easy_setopt(hCurl, CURLOPT_USERAGENT, S3fsCurl::userAgent.c_str());
}
return true;
}

View File

@ -236,6 +236,7 @@ class S3fsCurl
static curlprogress_t curl_progress;
static std::string curl_ca_bundle;
static mimes_t mimeTypes;
static std::string userAgent;
static int max_parallel_cnt;
static off_t multipart_size;
static bool is_sigv4;
@ -377,6 +378,7 @@ class S3fsCurl
static bool IsSignatureV4(void) { return S3fsCurl::is_sigv4; }
static bool SetUserAgentFlag(bool isset) { bool bresult = S3fsCurl::is_ua; S3fsCurl::is_ua = isset; return bresult; }
static bool IsUserAgentFlag(void) { return S3fsCurl::is_ua; }
static void InitUserAgent(void);
// methods
bool CreateCurlHandle(bool force = false);

View File

@ -4935,6 +4935,9 @@ int main(int argc, char* argv[])
exit(EXIT_FAILURE);
}
// set user agent
S3fsCurl::InitUserAgent();
// There's room for more command line error checking
// Check to see if the bucket name contains periods and https (SSL) is