]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[Core] Coverity: 1060958 Dereference before null check time_t2
authorAndrey Volk <andywolk@gmail.com>
Mon, 18 Sep 2023 21:16:58 +0000 (00:16 +0300)
committerAndrey Volk <andywolk@gmail.com>
Tue, 3 Oct 2023 14:27:15 +0000 (17:27 +0300)
[Core] Coverity: 1024236 Dereference before null check

[Core] Coverity: 1500370 Use of 32-bit time_t

[Core] Coverity: 1500255 Use of 32-bit time_t

[Core] Coverity: 1500245 Use of 32-bit time_t

[Core] Coverity: 1500250 Use of 32-bit time_t

[Core] Coverity: 1500244 Use of 32-bit time_t

[Core] Coverity: 1500235 Use of 32-bit time_t

[mod_pgsql] Coverity: 1227660 Logically dead code

[Core] Coverity: 1024552 Logically dead code

[Core] Coverity: 1500229 Use of 32-bit time_t

[Core] Coverity: 1500270 Use of 32-bit time_t

src/mod/databases/mod_pgsql/mod_pgsql.c
src/switch_core_media.c
src/switch_ivr.c
src/switch_ivr_originate.c
src/switch_rtp.c
src/switch_utils.c

index 0308f1f1fd7f70856d9eb996acb386c5800f3778..61250b3f20f13947e9147fe432830b9d66b6337e 100644 (file)
@@ -113,7 +113,7 @@ static int db_is_up(switch_pgsql_handle_t *handle)
        char *err_str = NULL;
        int max_tries = DEFAULT_PGSQL_RETRIES;
        int code = 0;
-       int recon = 0;
+       switch_status_t recon = SWITCH_STATUS_FALSE;
        switch_byte_t sanity = 255;
 
        if (handle) {
index ca6c05e0a9aae36f43ec4d9d7c17e32116ee04fe..2a13cb0c2e41ceed49e4289b5bf61ca7010f3a42 100644 (file)
@@ -2066,13 +2066,13 @@ SWITCH_DECLARE(switch_status_t) switch_media_handle_create(switch_media_handle_t
                switch_mutex_init(&session->media_handle->control_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 
                session->media_handle->engines[SWITCH_MEDIA_TYPE_AUDIO].ssrc =
-                       (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_AUDIO] + (uint32_t) time(NULL));
+                       (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_AUDIO] + (switch_time_t) time(NULL));
 
                session->media_handle->engines[SWITCH_MEDIA_TYPE_VIDEO].ssrc =
-                       (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_VIDEO] + (uint32_t) time(NULL) / 2);
+                       (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_VIDEO] + (switch_time_t) time(NULL) / 2);
 
                session->media_handle->engines[SWITCH_MEDIA_TYPE_TEXT].ssrc =
-                       (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_TEXT] + (uint32_t) time(NULL) / 2);
+                       (uint32_t) ((intptr_t) &session->media_handle->engines[SWITCH_MEDIA_TYPE_TEXT] + (switch_time_t) time(NULL) / 2);
 
 
 
@@ -10526,7 +10526,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
        }
 
        if (!smh->owner_id) {
-               smh->owner_id = (uint32_t) switch_epoch_time_now(NULL) - port;
+               smh->owner_id = (uint32_t)(switch_time_t)switch_epoch_time_now(NULL) - port;
        }
 
        if (!smh->session_id) {
@@ -11836,7 +11836,7 @@ SWITCH_DECLARE(void) switch_core_media_set_udptl_image_sdp(switch_core_session_t
        }
 
        if (!smh->owner_id) {
-               smh->owner_id = (uint32_t) switch_epoch_time_now(NULL) - port;
+               smh->owner_id = (uint32_t)(switch_time_t)switch_epoch_time_now(NULL) - port;
        }
 
        if (!smh->session_id) {
@@ -12050,7 +12050,7 @@ SWITCH_DECLARE(void) switch_core_media_patch_sdp(switch_core_session_t *session)
                                family = strchr(smh->mparams->sipip, ':') ? "IP6" : "IP4";
 
                                if (!smh->owner_id) {
-                                       smh->owner_id = (uint32_t) switch_epoch_time_now(NULL) * 31821U + 13849U;
+                                       smh->owner_id = (uint32_t)(switch_time_t)switch_epoch_time_now(NULL) * 31821U + 13849U;
                                }
 
                                if (!smh->session_id) {
index 7bfe0186f6ac438e98807054cd7b9aff3ea27889..0c0a444b2bb329a13a62a24cbf5a91d10cbf121d 100644 (file)
@@ -2814,7 +2814,7 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_call_stats(switch_xml_t xml, switch_core_
 static int switch_ivr_set_xml_chan_var(switch_xml_t xml, const char *var, const char *val, int off)
 {
        char *data;
-       switch_size_t dlen = strlen(val) * 3 + 1;
+       switch_size_t dlen = val ? strlen(val) * 3 + 1 : 1;
        switch_xml_t variable;
 
        if (!val) val = "";
index 0b06d6029cd96f541a3cffdea5f507dfbe3cda51..8903dc255f016313dcbe7a6838bc9dcfb99cf02c 100644 (file)
@@ -320,7 +320,7 @@ static int check_per_channel_timeouts(originate_global_t *oglobals,
                                delayed_min = oglobals->originate_status[i].per_channel_delay_start;
                        }
                }
-               early_exit_time = delayed_min - (uint32_t) elapsed;
+               early_exit_time = delayed_min - (uint32_t)(switch_time_t) elapsed;
        }
        for (i = 0; i < max; i++) {
                if (oglobals->originate_status[i].peer_channel && oglobals->originate_status[i].per_channel_delay_start &&
@@ -1305,7 +1305,7 @@ static switch_status_t setup_ringback(originate_global_t *oglobals, originate_st
                }
        }
 
-       if (oglobals->session && (read_codec = switch_core_session_get_read_codec(oglobals->session))) {
+       if ((read_codec = switch_core_session_get_read_codec(oglobals->session))) {
                if (ringback_data && switch_is_file_path(ringback_data)) {
                        if (!(strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR))) {
                                ringback->asis++;
index 17c93f2fa28069f241f4ecd2bcfd53816fa2486e..c644327d1991e5e0d20aabeeaf331c9104710a95 100644 (file)
@@ -4325,7 +4325,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session
                switch_sockaddr_create(&rtp_session->rtcp_from_addr, pool);
        }
        rtp_session->seq = (uint16_t) rand();
-       rtp_session->ssrc = (uint32_t) ((intptr_t) rtp_session + (uint32_t) switch_epoch_time_now(NULL));
+       rtp_session->ssrc = (uint32_t) ((intptr_t) rtp_session + (switch_time_t) switch_epoch_time_now(NULL));
 #ifdef DEBUG_TS_ROLLOVER
        rtp_session->last_write_ts = TS_ROLLOVER_START;
 #endif
@@ -8061,7 +8061,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
                /* If the marker was set, and the timestamp seems to have started over - set a new SSRC, to indicate this is a new stream */
                if (m && !switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_SEND) && (rtp_session->rtp_bugs & RTP_BUG_CHANGE_SSRC_ON_MARKER) &&
                        (rtp_session->flags[SWITCH_RTP_FLAG_RESET] || (rtp_session->ts <= rtp_session->last_write_ts && rtp_session->last_write_ts > 0))) {
-                       switch_rtp_set_ssrc(rtp_session, (uint32_t) ((intptr_t) rtp_session + (uint32_t) switch_epoch_time_now(NULL)));
+                       switch_rtp_set_ssrc(rtp_session, (uint32_t) ((intptr_t) rtp_session + (switch_time_t) switch_epoch_time_now(NULL)));
                }
 
                if (!switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_VIDEO) && !switch_rtp_test_flag(rtp_session, SWITCH_RTP_FLAG_UDPTL)) {
index c51953f0cffc34deb4d238b8989ee6569f1cb52b..ec7d05af451fc3655d330e98e34b71cce91400ed 100644 (file)
@@ -747,7 +747,7 @@ SWITCH_DECLARE(int) switch_parse_cidr(const char *string, ip_t *ip, ip_t *mask,
        ip_t *maskv = mask;
        ip_t *ipv = ip;
 
-       switch_copy_string(host, string, sizeof(host)-1);
+       switch_copy_string(host, string, sizeof(host) - 1);
        bit_str = strchr(host, '/');
 
        if (!bit_str) {
@@ -758,22 +758,20 @@ SWITCH_DECLARE(int) switch_parse_cidr(const char *string, ip_t *ip, ip_t *mask,
        bits = atoi(bit_str);
        ipv6 = strchr(string, ':');
        if (ipv6) {
-               int i,n;
+               int32_t i, n;
+               uint32_t k;
+
                if (bits < 0 || bits > 128) {
                        return -2;
                }
+
                bits = atoi(bit_str);
                switch_inet_pton(AF_INET6, host, (unsigned char *)ip);
-               for (n=bits,i=0 ;i < 16; i++){
-                       if (n >= 8) {
-                               maskv->v6.s6_addr[i] = 0xFF;
-                               n -= 8;
-                       } else if (n < 8) {
-                               maskv->v6.s6_addr[i] = 0xFF & ~(0xFF >> n);
-                               n -= n;
-                       } else if (n == 0) {
-                               maskv->v6.s6_addr[i] = 0x00;
-                       }
+
+               for (n = bits, i = 0; i < 16; i++) {
+                       k = 8 + ((n - 8) & ((n - 8) >> 31)); /* k = (n > 8) ? 8 : n */
+                       maskv->v6.s6_addr[i] = 0xFF & ~(0xFF >> k);     /* k = 0 gives 0x00, k = 8 gives 0xFF */
+                       n -= k;
                }
        } else {
                if (bits < 0 || bits > 32) {
@@ -786,6 +784,7 @@ SWITCH_DECLARE(int) switch_parse_cidr(const char *string, ip_t *ip, ip_t *mask,
 
                maskv->v4 = 0xFFFFFFFF & ~(0xFFFFFFFF >> bits);
        }
+
        *bitp = bits;
 
        return 0;
@@ -1161,7 +1160,7 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
                switch_safe_free(dupfile);
        }
 
-       switch_snprintf(filename, 80, "%s%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, (int) switch_epoch_time_now(NULL), rand() & 0xffff);
+       switch_snprintf(filename, 80, "%s%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, (int)(switch_time_t)switch_epoch_time_now(NULL), rand() & 0xffff);
 
        if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) > -1) {
                if (file) {