1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Replace sprintf with snprintf to eliminate compile warnings. v6.0.45 (#3534)

* Replaced all occurrences of sprintf with snprintf to address deprecation warnings
* Ensured proper buffer size is passed to snprintf to prevent potential buffer overflows
* Ran tests to confirm that the changes do not introduce any new issues or regressions

---------

Co-authored-by: ChenGH <chengh_math@126.com>
This commit is contained in:
chundonglinlin 2023-05-14 13:04:21 +08:00 committed by GitHub
parent 0629beeb0a
commit c0e931ae7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 61 additions and 31 deletions

View file

@ -218,6 +218,16 @@ srs_error_t SrsSemiSecurityTransport::protect_rtcp(void* packet, int* nb_cipher)
return srs_success;
}
srs_error_t SrsSemiSecurityTransport::unprotect_rtp(void* packet, int* nb_plaintext)
{
return srs_success;
}
srs_error_t SrsSemiSecurityTransport::unprotect_rtcp(void* packet, int* nb_plaintext)
{
return srs_success;
}
SrsPlaintextTransport::SrsPlaintextTransport(ISrsRtcNetwork* s)
{
network_ = s;

View file

@ -134,6 +134,8 @@ public:
public:
srs_error_t protect_rtp(void* packet, int* nb_cipher);
srs_error_t protect_rtcp(void* packet, int* nb_cipher);
srs_error_t unprotect_rtp(void* packet, int* nb_plaintext);
srs_error_t unprotect_rtcp(void* packet, int* nb_plaintext);
};
// Plaintext transport, without DTLS or SRTP.

View file

@ -329,17 +329,20 @@ srs_error_t SrsDtlsCertificate::initialize()
// Show DTLS fingerprint
if (true) {
char fp[100] = {0};
char *p = fp;
unsigned char md[EVP_MAX_MD_SIZE];
unsigned int n = 0;
// TODO: FIXME: Unused variable.
/*int r = */X509_digest(dtls_cert, EVP_sha256(), md, &n);
char* fp = new char[3 * n];
SrsAutoFreeA(char, fp);
char *p = fp;
for (unsigned int i = 0; i < n; i++, ++p) {
sprintf(p, "%02X", md[i]);
p += 2;
int nb = snprintf(p, 3, "%02X", md[i]);
srs_assert(nb > 0 && nb < (3 * n - (p - fp)));
p += nb;
if(i < (n-1)) {
*p = ':';

View file

@ -42,7 +42,7 @@ namespace tencentcloud_api_sign {
SHA1_Final(digest, &ctx);
char c_sha1[SHA_DIGEST_LENGTH*2+1];
for (unsigned i = 0; i < SHA_DIGEST_LENGTH; ++i) {
sprintf(&c_sha1[i*2], "%02x", (unsigned int)digest[i]);
snprintf(&c_sha1[i*2], 3, "%02x", (unsigned int)digest[i]);
}
return c_sha1;
}
@ -67,7 +67,7 @@ namespace tencentcloud_api_sign {
HMAC_CTX_free(ctx);
#endif
for (unsigned i = 0; i != digest_len; ++i) {
sprintf(&c_hmacsha1[i*2], "%02x", (unsigned int)digest[i]);
snprintf(&c_hmacsha1[i*2], 3, "%02x", (unsigned int)digest[i]);
}
return c_hmacsha1;
}