diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c index 3d56cc840d411d4fd474a334e25528d8d385d8e2..d1c05abecbe2ef5837eb6dc53d9fbc1989fd36e3 100644 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -2374,6 +2374,7 @@ static char *callstate2str(int ind) static int transmit_response_bysession(struct skinnysession *s, struct skinny_req *req) { int res = 0; + unsigned long len; if (!s) { ast_log(LOG_WARNING, "Asked to transmit to a non-existent session!\n"); @@ -2382,7 +2383,10 @@ static int transmit_response_bysession(struct skinnysession *s, struct skinny_re ast_mutex_lock(&s->lock); - if ((letohl(req->len) > SKINNY_MAX_PACKET) || (letohl(req->len) < 0)) { + /* Don't optimize out assigning letohl() to len. It is necessary to guarantee that the comparison will always catch invalid values. + * letohl() may or may not return a signed value depending upon which definition is used. */ + len = letohl(req->len); + if (SKINNY_MAX_PACKET < len) { ast_log(LOG_WARNING, "transmit_response: the length of the request (%u) is out of bounds (%d)\n", letohl(req->len), SKINNY_MAX_PACKET); ast_mutex_unlock(&s->lock); return -1; diff --git a/channels/pjsip/dialplan_functions.c b/channels/pjsip/dialplan_functions.c index 8080f86a435eb8707c630066b01dd14e675a6434..e291110e22139cf2c99ec1a88aedd7c345c1ad84 100644 --- a/channels/pjsip/dialplan_functions.c +++ b/channels/pjsip/dialplan_functions.c @@ -866,11 +866,11 @@ static int media_offer_read_av(struct ast_sip_session *session, char *buf, /* add one since we'll include a comma */ size = strlen(ast_format_get_name(fmt)) + 1; - len -= size; - if ((len) < 0) { + if (len < size) { ao2_ref(fmt, -1); break; } + len -= size; /* no reason to use strncat here since we have already ensured buf has enough space, so strcat can be safely used */ diff --git a/funcs/func_curl.c b/funcs/func_curl.c index 7fd56beb4038270d19d21abc1ad8388658068ac4..beab0c144c1522d1af217a390181b7f01bedfcda 100644 --- a/funcs/func_curl.c +++ b/funcs/func_curl.c @@ -171,7 +171,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define CURLVERSION_ATLEAST(a,b,c) \ ((LIBCURL_VERSION_MAJOR > (a)) || ((LIBCURL_VERSION_MAJOR == (a)) && (LIBCURL_VERSION_MINOR > (b))) || ((LIBCURL_VERSION_MAJOR == (a)) && (LIBCURL_VERSION_MINOR == (b)) && (LIBCURL_VERSION_PATCH >= (c)))) -#define CURLOPT_SPECIAL_HASHCOMPAT -500 +#define CURLOPT_SPECIAL_HASHCOMPAT ((CURLoption) -500) static void curlds_free(void *data); diff --git a/include/asterisk/app.h b/include/asterisk/app.h index d70d8a6f2eb53bdf3bf782230e7dc7a538b75d8f..6171dd4f26e029a409e875990f314ca842a5d029 100644 --- a/include/asterisk/app.h +++ b/include/asterisk/app.h @@ -985,6 +985,8 @@ int ast_play_and_wait(struct ast_channel *chan, const char *fn); * \since 12 */ enum ast_record_if_exists { + /*! Return an Error State for IF_Exists */ + AST_RECORD_IF_EXISTS_ERROR = -1, /*! Fail the recording. */ AST_RECORD_IF_EXISTS_FAIL, /*! Overwrite the existing recording. */ diff --git a/include/asterisk/cel.h b/include/asterisk/cel.h index 833b48b85c20c1f8202f05e7a5abb9be5e7d77e5..350b4bf9f8341e438ac76d26c365520fcad9ec7d 100644 --- a/include/asterisk/cel.h +++ b/include/asterisk/cel.h @@ -39,6 +39,8 @@ extern "C" { * \brief CEL event types */ enum ast_cel_event_type { + AST_CEL_INVALID_VALUE = -1, + AST_CEL_ALL = 0, /*! \brief channel birth */ AST_CEL_CHANNEL_START = 1, /*! \brief channel end */ @@ -75,7 +77,7 @@ enum ast_cel_event_type { AST_CEL_LOCAL_OPTIMIZE = 17, }; -/*! +/*! * \brief Check to see if CEL is enabled * * \since 1.8 diff --git a/include/asterisk/logger.h b/include/asterisk/logger.h index efaac4887270ec60251dd7b4a61be13e2dafd4b4..c701d17cea1c7a9de94358d9aec313bd4a892db9 100644 --- a/include/asterisk/logger.h +++ b/include/asterisk/logger.h @@ -371,7 +371,7 @@ void ast_callid_strnprint(char *buffer, size_t buffer_size, ast_callid callid); #define DEBUG_ATLEAST(level) \ (option_debug >= (level) \ - || (ast_opt_dbg_module && ast_debug_get_by_module(AST_MODULE) >= (level))) + || (ast_opt_dbg_module && (int)ast_debug_get_by_module(AST_MODULE) >= (level))) /*! * \brief Log a DEBUG message diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index bbcc2da938d1f9869660eaf12565150b594a0b1f..f3f571972e2cc695030aa69fa24e24070a5ba241 100644 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -816,7 +816,7 @@ int ast_safe_mkdir(const char *base_path, const char *path, int mode); * \param a the array to bound check * \return 0 if value out of bounds, otherwise true (non-zero) */ -#define ARRAY_IN_BOUNDS(v, a) IN_BOUNDS(v, 0, ARRAY_LEN(a) - 1) +#define ARRAY_IN_BOUNDS(v, a) IN_BOUNDS((int) (v), 0, ARRAY_LEN(a) - 1) /* Definition for Digest authorization */ struct ast_http_digest { diff --git a/main/app.c b/main/app.c index f3fc2980f52607c28628b391269b741307cde688..37afe42978499d34b29013c24447051af31ba95f 100644 --- a/main/app.c +++ b/main/app.c @@ -1515,6 +1515,9 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, case AST_RECORD_IF_EXISTS_APPEND: ioflags |= O_APPEND; break; + case AST_RECORD_IF_EXISTS_ERROR: + ast_assert(0); + break; } if (silencethreshold < 0) { diff --git a/main/cel.c b/main/cel.c index 93655c741b2fad6730c8de5597a1e4f4c0c7afcd..0c1e37b68944558962ac2498a279cb4d1760122f 100644 --- a/main/cel.c +++ b/main/cel.c @@ -284,7 +284,7 @@ static struct aco_type *general_options[] = ACO_TYPES(&general_option); * \brief Map of ast_cel_event_type to strings */ static const char * const cel_event_types[CEL_MAX_EVENT_IDS] = { - [0] = "ALL", + [AST_CEL_ALL] = "ALL", [AST_CEL_CHANNEL_START] = "CHAN_START", [AST_CEL_CHANNEL_END] = "CHAN_END", [AST_CEL_ANSWER] = "ANSWER", @@ -524,16 +524,13 @@ enum ast_cel_event_type ast_cel_str_to_event_type(const char *name) unsigned int i; for (i = 0; i < ARRAY_LEN(cel_event_types); i++) { - if (!cel_event_types[i]) { - continue; - } - - if (!strcasecmp(name, cel_event_types[i])) { + if (cel_event_types[i] && !strcasecmp(name, cel_event_types[i])) { return i; } } - return -1; + ast_log(LOG_ERROR, "Unknown event name '%s'\n", name); + return AST_CEL_INVALID_VALUE; } static int ast_cel_track_event(enum ast_cel_event_type et) @@ -563,11 +560,10 @@ static int events_handler(const struct aco_option *opt, struct ast_variable *var event_type = ast_cel_str_to_event_type(cur_event); - if (event_type == 0) { + if (event_type == AST_CEL_ALL) { /* All events */ cfg->events = (int64_t) -1; - } else if (event_type == -1) { - ast_log(LOG_ERROR, "Unknown event name '%s'\n", cur_event); + } else if (event_type == AST_CEL_INVALID_VALUE) { return -1; } else { cfg->events |= ((int64_t) 1 << event_type); diff --git a/main/enum.c b/main/enum.c index e36a9c745696d1df60de944363430fba4a715aea..bae12996565c7e47f32b2d035c9579fffdbeee68 100644 --- a/main/enum.c +++ b/main/enum.c @@ -257,7 +257,7 @@ struct ebl_context { static int ebl_callback(void *context, unsigned char *answer, int len, unsigned char *fullanswer) { struct ebl_context *c = context; - unsigned int i; + int i; c->pos = 0; /* default to empty */ c->separator[0] = 0; diff --git a/main/event.c b/main/event.c index 92adc036843f71767e74b5e2b1e5948b92116d3d..8880b9699329c4a1bc27e2c75e9eaa4d90365508 100644 --- a/main/event.c +++ b/main/event.c @@ -199,7 +199,7 @@ const char *ast_event_get_type_name(const struct ast_event *event) type = ast_event_get_type(event); - if (type < 0 || type >= ARRAY_LEN(event_names)) { + if (type >= ARRAY_LEN(event_names)) { ast_log(LOG_ERROR, "Invalid event type - '%u'\n", type); return ""; } diff --git a/main/indications.c b/main/indications.c index af9cfc8ef7c5903d45c36baadfd274ec6e145145..02a68b7caca7d3b15f6e77eaacffd3c7cda9dc48 100644 --- a/main/indications.c +++ b/main/indications.c @@ -359,14 +359,13 @@ int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst, if (tone_data.midinote) { /* midi notes must be between 0 and 127 */ - - if (tone_data.freq1 >= 0 && tone_data.freq1 <= 127) { + if (tone_data.freq1 <= 127) { tone_data.freq1 = midi_tohz[tone_data.freq1]; } else { tone_data.freq1 = 0; } - if (tone_data.freq2 >= 0 && tone_data.freq2 <= 127) { + if (tone_data.freq2 <= 127) { tone_data.freq2 = midi_tohz[tone_data.freq2]; } else { tone_data.freq2 = 0; diff --git a/main/presencestate.c b/main/presencestate.c index 529979bac756ccbf180ce6566bb7ac97fa0fc078..4b3e94e61b37f7b3dad4402dd4960d04bcbcb99c 100644 --- a/main/presencestate.c +++ b/main/presencestate.c @@ -323,7 +323,7 @@ static void do_presence_state_change(const char *provider) state = ast_presence_state_helper(provider, &subtype, &message, 0); - if (state < 0) { + if (state == AST_PRESENCE_INVALID) { return; } diff --git a/main/security_events.c b/main/security_events.c index 0546bfe73804eab09fc8c0049efcb90ad67736d2..5a8df66d1188f951d6ca72cd51d7aa6c28d7e834 100644 --- a/main/security_events.c +++ b/main/security_events.c @@ -886,7 +886,7 @@ const char *ast_security_event_severity_get_name( static int check_event_type(const enum ast_security_event_type event_type) { - if (event_type < 0 || event_type >= AST_SECURITY_EVENT_NUM_TYPES) { + if (event_type >= AST_SECURITY_EVENT_NUM_TYPES) { ast_log(LOG_ERROR, "Invalid security event type %u\n", event_type); return -1; } @@ -1172,7 +1172,7 @@ return_error: int ast_security_event_report(const struct ast_security_event_common *sec) { - if (sec->event_type < 0 || sec->event_type >= AST_SECURITY_EVENT_NUM_TYPES) { + if (sec->event_type >= AST_SECURITY_EVENT_NUM_TYPES) { ast_log(LOG_ERROR, "Invalid security event type\n"); return -1; } diff --git a/main/udptl.c b/main/udptl.c index 91458489d846a82bf5e78dbf7a3c7950a000fb63..4e878195c46846a0fa13cdccdd2f8aafa43e50de 100644 --- a/main/udptl.c +++ b/main/udptl.c @@ -362,8 +362,7 @@ static int encode_open_type(const struct ast_udptl *udptl, uint8_t *buf, unsigne } /* Encode the open type */ for (octet_idx = 0; ; num_octets -= enclen, octet_idx += enclen) { - if ((enclen = encode_length(buf, len, num_octets)) < 0) - return -1; + enclen = encode_length(buf, len, num_octets); if (enclen + *len > buflen) { ast_log(LOG_ERROR, "UDPTL (%s): Buffer overflow detected (%u + %u > %u)\n", LOG_TAG(udptl), enclen, *len, buflen); @@ -646,8 +645,7 @@ static int udptl_build_packet(struct ast_udptl *s, uint8_t *buf, unsigned int bu buf[len++] = 0x00; /* The number of entries will always be zero, so it is pointless allowing for the fragmented case here. */ - if (encode_length(buf, &len, 0) < 0) - return -1; + encode_length(buf, &len, 0); break; case UDPTL_ERROR_CORRECTION_REDUNDANCY: /* Encode the error recovery type */ @@ -658,8 +656,7 @@ static int udptl_build_packet(struct ast_udptl *s, uint8_t *buf, unsigned int bu entries = s->tx_seq_no; /* The number of entries will always be small, so it is pointless allowing for the fragmented case here. */ - if (encode_length(buf, &len, entries) < 0) - return -1; + encode_length(buf, &len, entries); /* Encode the elements */ for (i = 0; i < entries; i++) { j = (entry - i - 1) & UDPTL_BUF_MASK; diff --git a/res/ari/resource_bridges.c b/res/ari/resource_bridges.c index bcd27af146d2ad4a4d1ea9f8e4ed507b5abcbc3e..5914a071134c029b6bdcbff092cb751cb73a565a 100644 --- a/res/ari/resource_bridges.c +++ b/res/ari/resource_bridges.c @@ -692,7 +692,7 @@ void ast_ari_bridges_record(struct ast_variable *headers, return; } - if (options->if_exists == -1) { + if (options->if_exists == AST_RECORD_IF_EXISTS_ERROR) { ast_ari_response_error( response, 400, "Bad Request", "ifExists invalid"); diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c index fb1aa039c674dc013ecdba787b1bdf7089fc2b60..59431583171d64fa06359cf55989c7db43ead986 100644 --- a/res/ari/resource_channels.c +++ b/res/ari/resource_channels.c @@ -626,7 +626,7 @@ void ast_ari_channels_record(struct ast_variable *headers, return; } - if (options->if_exists == -1) { + if (options->if_exists == AST_RECORD_IF_EXISTS_ERROR) { ast_ari_response_error( response, 400, "Bad Request", "ifExists invalid"); diff --git a/res/res_pjsip_exten_state.c b/res/res_pjsip_exten_state.c index 45bfff605e488ad10711c1886147ab6b6247ace3..da9b133f9c2f46bc71b1f69ddda93a2bcf42c79d 100644 --- a/res/res_pjsip_exten_state.c +++ b/res/res_pjsip_exten_state.c @@ -401,6 +401,7 @@ static struct ast_sip_exten_state_data *exten_state_data_alloc(struct ast_sip_su struct ast_sip_exten_state_data *exten_state_data; char *subtype = NULL; char *message = NULL; + int presence_state; exten_state_data = ao2_alloc(sizeof(*exten_state_data), exten_state_data_destructor); if (!exten_state_data) { @@ -408,11 +409,12 @@ static struct ast_sip_exten_state_data *exten_state_data_alloc(struct ast_sip_su } exten_state_data->exten = exten_state_sub->exten; - if ((exten_state_data->presence_state = ast_hint_presence_state(NULL, exten_state_sub->context, - exten_state_sub->exten, &subtype, &message)) == -1) { + presence_state = ast_hint_presence_state(NULL, exten_state_sub->context, exten_state_sub->exten, &subtype, &message); + if (presence_state == -1 || presence_state == AST_PRESENCE_INVALID) { ao2_cleanup(exten_state_data); return NULL; } + exten_state_data->presence_state = presence_state; exten_state_data->presence_subtype = subtype; exten_state_data->presence_message = message; exten_state_data->user_agent = exten_state_sub->user_agent; diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c index 1de774ff5edba814915691e4cb70a099f5056a8f..2eac55f190c23cd2067693835181d205d55262fb 100644 --- a/res/res_stasis_playback.c +++ b/res/res_stasis_playback.c @@ -629,9 +629,9 @@ enum stasis_playback_oper_results stasis_app_playback_operation( playback_opreation_cb cb; SCOPED_AO2LOCK(lock, playback); - ast_assert(playback->state >= 0 && playback->state < STASIS_PLAYBACK_STATE_MAX); + ast_assert(playback->state < STASIS_PLAYBACK_STATE_MAX); - if (operation < 0 || operation >= STASIS_PLAYBACK_MEDIA_OP_MAX) { + if (operation >= STASIS_PLAYBACK_MEDIA_OP_MAX) { ast_log(LOG_ERROR, "Invalid playback operation %u\n", operation); return -1; } diff --git a/res/res_stasis_recording.c b/res/res_stasis_recording.c index 433adb3d5018f7d5b3be4fe915ec846a4d714392..df7f8b33a548f6eaf4ca60d3cab1bdb9b6b9249e 100644 --- a/res/res_stasis_recording.c +++ b/res/res_stasis_recording.c @@ -212,7 +212,7 @@ enum ast_record_if_exists stasis_app_recording_if_exists_parse( return AST_RECORD_IF_EXISTS_APPEND; } - return -1; + return AST_RECORD_IF_EXISTS_ERROR; } static void recording_publish(struct stasis_app_recording *recording, const char *cause) @@ -595,13 +595,13 @@ enum stasis_app_recording_oper_results stasis_app_recording_operation( recording_operation_cb cb; SCOPED_AO2LOCK(lock, recording); - if (recording->state < 0 || recording->state >= STASIS_APP_RECORDING_STATE_MAX) { + if (recording->state >= STASIS_APP_RECORDING_STATE_MAX) { ast_log(LOG_WARNING, "Invalid recording state %u\n", recording->state); return -1; } - if (operation < 0 || operation >= STASIS_APP_RECORDING_OPER_MAX) { + if (operation >= STASIS_APP_RECORDING_OPER_MAX) { ast_log(LOG_WARNING, "Invalid recording operation %u\n", operation); return -1;