code
stringlengths 14
2.05k
| label
int64 0
1
| programming_language
stringclasses 7
values | cwe_id
stringlengths 6
14
| cwe_name
stringlengths 5
98
⌀ | description
stringlengths 36
379
⌀ | url
stringlengths 36
48
⌀ | label_name
stringclasses 2
values |
---|---|---|---|---|---|---|---|
simple_upscale(j_decompress_ptr cinfo,
JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
{
do {
#if BITS_IN_JSAMPLE == 12
/* 12-bit is the only data precision for which the range of the sample data
* type exceeds the valid sample range. Thus, we need to range-limit the
* samples, because other algorithms may try to use them as array indices.
*/
*output_buf++ = (_JSAMPLE)((*diff_buf++ << cinfo->Al) & 0xFFF);
#else
*output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
#endif
} while (--width);
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
noscale(j_decompress_ptr cinfo,
JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
{
do {
#if BITS_IN_JSAMPLE == 12
*output_buf++ = (_JSAMPLE)((*diff_buf++) & 0xFFF);
#else
*output_buf++ = (_JSAMPLE)(*diff_buf++);
#endif
} while (--width);
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
print_perm_line (int idx,
GPtrArray *items,
int cols)
{
g_autoptr(GString) res = g_string_new (NULL);
g_autofree char *escaped_first_perm = NULL;
int i;
escaped_first_perm = flatpak_escape_string (items->pdata[0], FLATPAK_ESCAPE_DEFAULT);
g_string_append_printf (res, " [%d] %s", idx, escaped_first_perm);
for (i = 1; i < items->len; i++)
{
g_autofree char *escaped = flatpak_escape_string (items->pdata[i],
FLATPAK_ESCAPE_DEFAULT);
char *p;
int len;
p = strrchr (res->str, '\n');
if (!p)
p = res->str;
len = (res->str + strlen (res->str)) - p;
if (len + strlen (escaped) + 2 >= cols)
g_string_append_printf (res, ",\n %s", escaped);
else
g_string_append_printf (res, ", %s", escaped);
}
g_print ("%s\n", res->str);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
load_kernel_module_list (void)
{
GHashTable *modules = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
g_autofree char *modules_data = NULL;
g_autoptr(GError) error = NULL;
char *start, *end;
if (!g_file_get_contents ("/proc/modules", &modules_data, NULL, &error))
{
g_info ("Failed to read /proc/modules: %s", error->message);
return modules;
}
/* /proc/modules is a table of modules.
* Columns are split by spaces and rows by newlines.
* The first column is the name. */
start = modules_data;
while (TRUE)
{
end = strchr (start, ' ');
if (end == NULL)
break;
g_hash_table_add (modules, g_strndup (start, (end - start)));
start = strchr (end, '\n');
if (start == NULL)
break;
start++;
}
return modules;
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
append_hex_escaped_character (GString *result,
gunichar c)
{
if (c <= 0xFF)
g_string_append_printf (result, "\\x%02X", c);
else if (c <= 0xFFFF)
g_string_append_printf (result, "\\u%04X", c);
else
g_string_append_printf (result, "\\U%08X", c);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
flatpak_print_escaped_string (const char *s,
FlatpakEscapeFlags flags)
{
g_autofree char *escaped = flatpak_escape_string (s, flags);
g_print ("%s", escaped);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
is_char_safe (gunichar c)
{
return g_unichar_isgraph (c) || c == ' ';
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
should_hex_escape (gunichar c,
FlatpakEscapeFlags flags)
{
if ((flags & FLATPAK_ESCAPE_ALLOW_NEWLINES) && c == '\n')
return FALSE;
return !is_char_safe (c);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
flatpak_escape_string (const char *s,
FlatpakEscapeFlags flags)
{
g_autoptr(GString) res = g_string_new ("");
gboolean did_escape = FALSE;
while (*s)
{
gunichar c = g_utf8_get_char_validated (s, -1);
if (c == (gunichar)-2 || c == (gunichar)-1)
{
/* Need to convert to unsigned first, to avoid negative chars becoming
huge gunichars. */
append_hex_escaped_character (res, (unsigned char)*s++);
did_escape = TRUE;
continue;
}
else if (should_hex_escape (c, flags))
{
append_hex_escaped_character (res, c);
did_escape = TRUE;
}
else if (c == '\\' || (!(flags & FLATPAK_ESCAPE_DO_NOT_QUOTE) && c == '\''))
{
g_string_append_printf (res, "\\%c", (char) c);
did_escape = TRUE;
}
else
g_string_append_unichar (res, c);
s = g_utf8_find_next_char (s, NULL);
}
if (did_escape && !(flags & FLATPAK_ESCAPE_DO_NOT_QUOTE))
{
g_string_prepend_c (res, '\'');
g_string_append_c (res, '\'');
}
return g_string_free (g_steal_pointer (&res), FALSE);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
test_string_escape (void)
{
gsize idx;
for (idx = 0; idx < G_N_ELEMENTS (escapes); idx++)
{
EscapeData *data = &escapes[idx];
g_autofree char *ret = NULL;
ret = flatpak_escape_string (data->in, data->flags);
g_assert_cmpstr (ret, ==, data->out);
}
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
option_persist_cb (const gchar *option_name,
const gchar *value,
gpointer data,
GError **error)
{
FlatpakContext *context = data;
return flatpak_context_set_persistent (context, value, error);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
flatpak_context_set_persistent (FlatpakContext *context,
const char *path,
GError **error)
{
if (!flatpak_validate_path_characters (path, error))
return FALSE;
g_hash_table_insert (context->persistent, g_strdup (path), GINT_TO_POINTER (1));
return TRUE;
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
flatpak_validate_path_characters (const char *path,
GError **error)
{
while (*path)
{
gunichar c = g_utf8_get_char_validated (path, -1);
if (c == (gunichar)-1 || c == (gunichar)-2)
{
/* Need to convert to unsigned first, to avoid negative chars becoming
huge gunichars. */
g_autofree char *escaped_char = escape_character ((unsigned char)*path);
g_autofree char *escaped = flatpak_escape_string (path, FLATPAK_ESCAPE_DEFAULT);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
"Non-UTF8 byte %s in path %s", escaped_char, escaped);
return FALSE;
}
else if (!is_char_safe (c))
{
g_autofree char *escaped_char = escape_character (c);
g_autofree char *escaped = flatpak_escape_string (path, FLATPAK_ESCAPE_DEFAULT);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
"Non-graphical character %s in path %s", escaped_char, escaped);
return FALSE;
}
path = g_utf8_find_next_char (path, NULL);
}
return TRUE;
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
escape_character (gunichar c)
{
g_autoptr(GString) res = g_string_new ("");
append_hex_escaped_character (res, c);
return g_string_free (g_steal_pointer (&res), FALSE);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/context/env", test_context_env);
g_test_add_func ("/context/env-fd", test_context_env_fd);
g_test_add_func ("/context/merge-fs", test_context_merge_fs);
g_test_add_func ("/context/validate-path-args", test_validate_path_args);
g_test_add_func ("/context/validate-path-meta", test_validate_path_meta);
return g_test_run ();
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
test_validate_path_meta (void)
{
gsize idx;
for (idx = 0; idx < G_N_ELEMENTS (invalid_path_meta); idx++)
{
g_autoptr(FlatpakContext) context = flatpak_context_new ();
g_autoptr(GKeyFile) metakey = g_key_file_new ();
g_autoptr(GError) local_error = NULL;
PathValidityData *data = &invalid_path_meta[idx];
gboolean ret = FALSE;
g_key_file_set_string_list (metakey, FLATPAK_METADATA_GROUP_CONTEXT,
data->key, &data->value, 1);
ret = flatpak_context_load_metadata (context, metakey, &local_error);
g_assert_false (ret);
g_assert_error (local_error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA);
g_assert (strstr (local_error->message, "Non-graphical character"));
}
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
test_validate_path_args (void)
{
gsize idx;
for (idx = 0; idx < G_N_ELEMENTS (invalid_path_args); idx++)
{
g_autoptr(FlatpakContext) context = flatpak_context_new ();
g_autoptr(GError) local_error = NULL;
const char *path = invalid_path_args[idx];
context_parse_args (context, &local_error, path, NULL);
g_assert_error (local_error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA);
g_assert (strstr (local_error->message, "Non-graphical character"));
}
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
context_parse_args (FlatpakContext *context,
GError **error,
...)
{
g_autoptr(GOptionContext) oc = NULL;
g_autoptr(GOptionGroup) group = NULL;
g_autoptr(GPtrArray) args = g_ptr_array_new_with_free_func (g_free);
g_auto(GStrv) argv = NULL;
const char *arg;
va_list ap;
g_ptr_array_add (args, g_strdup ("argv[0]"));
va_start (ap, error);
while ((arg = va_arg (ap, const char *)) != NULL)
g_ptr_array_add (args, g_strdup (arg));
va_end (ap);
g_ptr_array_add (args, NULL);
argv = (GStrv) g_ptr_array_free (g_steal_pointer (&args), FALSE);
oc = g_option_context_new ("");
group = flatpak_context_get_options (context);
g_option_context_add_group (oc, group);
g_option_context_parse_strv (oc, &argv, error);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
test_validate_path_characters (void)
{
gsize idx;
for (idx = 0; idx < G_N_ELEMENTS (paths); idx++)
{
PathValidityData *data = &paths[idx];
gboolean ret = FALSE;
ret = flatpak_validate_path_characters (data->path, NULL);
g_assert_cmpint (ret, ==, data->ret);
}
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
int packet__queue(struct mosquitto *mosq, struct mosquitto__packet *packet)
{
#ifndef WITH_BROKER
char sockpair_data = 0;
#endif
assert(mosq);
assert(packet);
packet->pos = 0;
packet->to_process = packet->packet_length;
packet->next = NULL;
pthread_mutex_lock(&mosq->out_packet_mutex);
#ifdef WITH_BROKER
if(mosq->out_packet_count >= db.config->max_queued_messages){
mosquitto__free(packet);
if(mosq->is_dropping == false){
mosq->is_dropping = true;
log__printf(NULL, MOSQ_LOG_NOTICE,
"Outgoing messages are being dropped for client %s.",
mosq->id);
}
G_MSGS_DROPPED_INC();
return MOSQ_ERR_SUCCESS;
}
#endif
if(mosq->out_packet){
mosq->out_packet_last->next = packet;
}else{
mosq->out_packet = packet;
}
mosq->out_packet_last = packet;
mosq->out_packet_count++;
pthread_mutex_unlock(&mosq->out_packet_mutex);
#ifdef WITH_BROKER
# ifdef WITH_WEBSOCKETS
if(mosq->wsi){
lws_callback_on_writable(mosq->wsi);
return MOSQ_ERR_SUCCESS;
}else{
return packet__write(mosq);
}
# else
return packet__write(mosq);
# endif
#else
/* Write a single byte to sockpairW (connected to sockpairR) to break out
* of select() if in threaded mode. */
if(mosq->sockpairW != INVALID_SOCKET){
#ifndef WIN32
if(write(mosq->sockpairW, &sockpair_data, 1)){
}
#else
send(mosq->sockpairW, &sockpair_data, 1, 0);
#endif
}
if(mosq->in_callback == false && mosq->threaded == mosq_ts_none){
return packet__write(mosq);
}else{
return MOSQ_ERR_SUCCESS;
}
#endif
} | 1 | C | CWE-401 | Missing Release of Memory after Effective Lifetime | The product does not sufficiently track and release allocated memory after it has been used, which slowly consumes remaining memory. | https://cwe.mitre.org/data/definitions/401.html | safe |
struct mosquitto *context__init(mosq_sock_t sock)
{
struct mosquitto *context;
char address[1024];
context = mosquitto__calloc(1, sizeof(struct mosquitto));
if(!context) return NULL;
#ifdef WITH_EPOLL
context->ident = id_client;
#else
context->pollfd_index = -1;
#endif
mosquitto__set_state(context, mosq_cs_new);
context->sock = sock;
context->last_msg_in = db.now_s;
context->next_msg_out = db.now_s + 60;
context->keepalive = 60; /* Default to 60s */
context->clean_start = true;
context->id = NULL;
context->last_mid = 0;
context->will = NULL;
context->username = NULL;
context->password = NULL;
context->listener = NULL;
context->acl_list = NULL;
context->retain_available = true;
/* is_bridge records whether this client is a bridge or not. This could be
* done by looking at context->bridge for bridges that we create ourself,
* but incoming bridges need some other way of being recorded. */
context->is_bridge = false;
context->in_packet.payload = NULL;
packet__cleanup(&context->in_packet);
context->out_packet = NULL;
context->current_out_packet = NULL;
context->out_packet_count = 0;
context->address = NULL;
if((int)sock >= 0){
if(!net__socket_get_address(sock, address, 1024, &context->remote_port)){
context->address = mosquitto__strdup(address);
}
if(!context->address){
/* getpeername and inet_ntop failed and not a bridge */
mosquitto__free(context);
return NULL;
}
}
context->bridge = NULL;
context->msgs_in.inflight_maximum = 1;
context->msgs_out.inflight_maximum = db.config->max_inflight_messages;
context->msgs_in.inflight_quota = 1;
context->msgs_out.inflight_quota = db.config->max_inflight_messages;
context->max_qos = 2;
#ifdef WITH_TLS
context->ssl = NULL;
#endif
if((int)context->sock >= 0){
HASH_ADD(hh_sock, db.contexts_by_sock, sock, sizeof(context->sock), context);
}
return context;
} | 1 | C | CWE-401 | Missing Release of Memory after Effective Lifetime | The product does not sufficiently track and release allocated memory after it has been used, which slowly consumes remaining memory. | https://cwe.mitre.org/data/definitions/401.html | safe |
static void context__cleanup_out_packets(struct mosquitto *context)
{
struct mosquitto__packet *packet;
if(!context) return;
if(context->current_out_packet){
packet__cleanup(context->current_out_packet);
mosquitto__free(context->current_out_packet);
context->current_out_packet = NULL;
}
while(context->out_packet){
packet__cleanup(context->out_packet);
packet = context->out_packet;
context->out_packet = context->out_packet->next;
mosquitto__free(packet);
}
context->out_packet_count = 0;
} | 1 | C | CWE-401 | Missing Release of Memory after Effective Lifetime | The product does not sufficiently track and release allocated memory after it has been used, which slowly consumes remaining memory. | https://cwe.mitre.org/data/definitions/401.html | safe |
void context__cleanup(struct mosquitto *context, bool force_free)
{
if(!context) return;
if(force_free){
context->clean_start = true;
}
#ifdef WITH_BRIDGE
if(context->bridge){
bridge__cleanup(context);
}
#endif
alias__free_all(context);
context__cleanup_out_packets(context);
mosquitto__free(context->auth_method);
context->auth_method = NULL;
mosquitto__free(context->username);
context->username = NULL;
mosquitto__free(context->password);
context->password = NULL;
net__socket_close(context);
if(force_free){
sub__clean_session(context);
}
db__messages_delete(context, force_free);
mosquitto__free(context->address);
context->address = NULL;
context__send_will(context);
if(context->id){
context__remove_from_by_id(context);
mosquitto__free(context->id);
context->id = NULL;
}
packet__cleanup(&(context->in_packet));
context__cleanup_out_packets(context);
#if defined(WITH_BROKER) && defined(__GLIBC__) && defined(WITH_ADNS)
if(context->adns){
gai_cancel(context->adns);
mosquitto__free((struct addrinfo *)context->adns->ar_request);
mosquitto__free(context->adns);
}
#endif
if(force_free){
mosquitto__free(context);
}
} | 1 | C | CWE-401 | Missing Release of Memory after Effective Lifetime | The product does not sufficiently track and release allocated memory after it has been used, which slowly consumes remaining memory. | https://cwe.mitre.org/data/definitions/401.html | safe |
int db__message_store_find(struct mosquitto *context, uint16_t mid, struct mosquitto_client_msg **client_msg)
{
struct mosquitto_client_msg *cmsg;
*client_msg = NULL;
if(!context) return MOSQ_ERR_INVAL;
DL_FOREACH(context->msgs_in.inflight, cmsg){
if(cmsg->store->source_mid == mid){
*client_msg = cmsg;
return MOSQ_ERR_SUCCESS;
}
}
DL_FOREACH(context->msgs_in.queued, cmsg){
if(cmsg->store->source_mid == mid){
*client_msg = cmsg;
return MOSQ_ERR_SUCCESS;
}
}
return 1;
} | 1 | C | CWE-401 | Missing Release of Memory after Effective Lifetime | The product does not sufficiently track and release allocated memory after it has been used, which slowly consumes remaining memory. | https://cwe.mitre.org/data/definitions/401.html | safe |
static int db__message_reconnect_reset_incoming(struct mosquitto *context)
{
struct mosquitto_client_msg *msg, *tmp;
context->msgs_in.inflight_bytes = 0;
context->msgs_in.inflight_bytes12 = 0;
context->msgs_in.inflight_count = 0;
context->msgs_in.inflight_count12 = 0;
context->msgs_in.queued_bytes = 0;
context->msgs_in.queued_bytes12 = 0;
context->msgs_in.queued_count = 0;
context->msgs_in.queued_count12 = 0;
context->msgs_in.inflight_quota = context->msgs_in.inflight_maximum;
DL_FOREACH_SAFE(context->msgs_in.inflight, msg, tmp){
db__msg_add_to_inflight_stats(&context->msgs_in, msg);
if(msg->qos > 0){
util__decrement_receive_quota(context);
}
if(msg->qos != 2){
/* Anything <QoS 2 can be completely retried by the client at
* no harm. */
db__message_remove_from_inflight(&context->msgs_in, msg);
}else{
/* Message state can be preserved here because it should match
* whatever the client has got. */
msg->dup = 0;
}
}
/* Messages received when the client was disconnected are put
* in the mosq_ms_queued state. If we don't change them to the
* appropriate "publish" state, then the queued messages won't
* get sent until the client next receives a message - and they
* will be sent out of order.
*/
DL_FOREACH_SAFE(context->msgs_in.queued, msg, tmp){
msg->dup = 0;
db__msg_add_to_queued_stats(&context->msgs_in, msg);
if(db__ready_for_flight(context, mosq_md_in, msg->qos)){
switch(msg->qos){
case 0:
msg->state = mosq_ms_publish_qos0;
break;
case 1:
msg->state = mosq_ms_publish_qos1;
break;
case 2:
msg->state = mosq_ms_publish_qos2;
break;
}
db__message_dequeue_first(context, &context->msgs_in);
}
}
return MOSQ_ERR_SUCCESS;
} | 1 | C | CWE-401 | Missing Release of Memory after Effective Lifetime | The product does not sufficiently track and release allocated memory after it has been used, which slowly consumes remaining memory. | https://cwe.mitre.org/data/definitions/401.html | safe |
escape(unsigned char ch, char *buf)
{
const int len = ch < 0100 ? (ch < 010 ? 3 : 4) : 5;
/* Work backwards from the least significant digit to most significant. */
switch (len) {
case 5:
buf[4] = (ch & 7) + '0';
ch >>= 3;
FALLTHROUGH;
case 4:
buf[3] = (ch & 7) + '0';
ch >>= 3;
FALLTHROUGH;
case 3:
buf[2] = (ch & 7) + '0';
buf[1] = '0';
buf[0] = '#';
break;
}
buf[len] = '\0';
return len;
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
escape(unsigned char ch, char *buf)
{
const int len = ch < 0100 ? (ch < 010 ? 3 : 4) : 5;
/* Work backwards from the least significant digit to most significant. */
switch (len) {
case 5:
buf[4] = (ch & 7) + '0';
ch >>= 3;
FALLTHROUGH;
case 4:
buf[3] = (ch & 7) + '0';
ch >>= 3;
FALLTHROUGH;
case 3:
buf[2] = (ch & 7) + '0';
buf[1] = '0';
buf[0] = '#';
break;
}
buf[len] = '\0';
return len;
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
sudo_lbuf_append_esc_v1(struct sudo_lbuf *lbuf, int flags, const char *fmt, ...)
{
unsigned int saved_len = lbuf->len;
bool ret = false;
const char *s;
va_list ap;
debug_decl(sudo_lbuf_append_esc, SUDO_DEBUG_UTIL);
if (sudo_lbuf_error(lbuf))
debug_return_bool(false);
#define should_escape(ch) \
((ISSET(flags, LBUF_ESC_CNTRL) && iscntrl((unsigned char)ch)) || \
(ISSET(flags, LBUF_ESC_BLANK) && isblank((unsigned char)ch)))
#define should_quote(ch) \
(ISSET(flags, LBUF_ESC_QUOTE) && (ch == '\'' || ch == '\\'))
va_start(ap, fmt);
while (*fmt != '\0') {
if (fmt[0] == '%' && fmt[1] == 's') {
if ((s = va_arg(ap, char *)) == NULL)
s = "(NULL)";
while (*s != '\0') {
if (should_escape(*s)) {
if (!sudo_lbuf_expand(lbuf, sizeof("#0177") - 1))
goto done;
lbuf->len += escape(*s++, lbuf->buf + lbuf->len);
continue;
}
if (should_quote(*s)) {
if (!sudo_lbuf_expand(lbuf, 2))
goto done;
lbuf->buf[lbuf->len++] = '\\';
lbuf->buf[lbuf->len++] = *s++;
continue;
}
if (!sudo_lbuf_expand(lbuf, 1))
goto done;
lbuf->buf[lbuf->len++] = *s++;
}
fmt += 2;
continue;
}
if (should_escape(*fmt)) {
if (!sudo_lbuf_expand(lbuf, sizeof("#0177") - 1))
goto done;
if (*fmt == '\'') {
lbuf->buf[lbuf->len++] = '\\';
lbuf->buf[lbuf->len++] = *fmt++;
} else {
lbuf->len += escape(*fmt++, lbuf->buf + lbuf->len);
}
continue;
}
if (!sudo_lbuf_expand(lbuf, 1))
goto done;
lbuf->buf[lbuf->len++] = *fmt++;
}
ret = true;
done:
if (!ret)
lbuf->len = saved_len;
if (lbuf->size != 0)
lbuf->buf[lbuf->len] = '\0';
va_end(ap);
debug_return_bool(ret);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
sudo_lbuf_append_esc_v1(struct sudo_lbuf *lbuf, int flags, const char *fmt, ...)
{
unsigned int saved_len = lbuf->len;
bool ret = false;
const char *s;
va_list ap;
debug_decl(sudo_lbuf_append_esc, SUDO_DEBUG_UTIL);
if (sudo_lbuf_error(lbuf))
debug_return_bool(false);
#define should_escape(ch) \
((ISSET(flags, LBUF_ESC_CNTRL) && iscntrl((unsigned char)ch)) || \
(ISSET(flags, LBUF_ESC_BLANK) && isblank((unsigned char)ch)))
#define should_quote(ch) \
(ISSET(flags, LBUF_ESC_QUOTE) && (ch == '\'' || ch == '\\'))
va_start(ap, fmt);
while (*fmt != '\0') {
if (fmt[0] == '%' && fmt[1] == 's') {
if ((s = va_arg(ap, char *)) == NULL)
s = "(NULL)";
while (*s != '\0') {
if (should_escape(*s)) {
if (!sudo_lbuf_expand(lbuf, sizeof("#0177") - 1))
goto done;
lbuf->len += escape(*s++, lbuf->buf + lbuf->len);
continue;
}
if (should_quote(*s)) {
if (!sudo_lbuf_expand(lbuf, 2))
goto done;
lbuf->buf[lbuf->len++] = '\\';
lbuf->buf[lbuf->len++] = *s++;
continue;
}
if (!sudo_lbuf_expand(lbuf, 1))
goto done;
lbuf->buf[lbuf->len++] = *s++;
}
fmt += 2;
continue;
}
if (should_escape(*fmt)) {
if (!sudo_lbuf_expand(lbuf, sizeof("#0177") - 1))
goto done;
if (*fmt == '\'') {
lbuf->buf[lbuf->len++] = '\\';
lbuf->buf[lbuf->len++] = *fmt++;
} else {
lbuf->len += escape(*fmt++, lbuf->buf + lbuf->len);
}
continue;
}
if (!sudo_lbuf_expand(lbuf, 1))
goto done;
lbuf->buf[lbuf->len++] = *fmt++;
}
ret = true;
done:
if (!ret)
lbuf->len = saved_len;
if (lbuf->size != 0)
lbuf->buf[lbuf->len] = '\0';
va_end(ap);
debug_return_bool(ret);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
expand_command(struct eventlog *evlog, char **newbuf)
{
size_t len, bufsize = strlen(evlog->command) + 1;
char *cp, *buf;
int ac;
debug_decl(expand_command, SUDO_DEBUG_UTIL);
if (evlog->argv == NULL || evlog->argv[0] == NULL || evlog->argv[1] == NULL) {
/* No arguments, we can use the command as-is. */
*newbuf = NULL;
debug_return_str(evlog->command);
}
/* Skip argv[0], we use evlog->command instead. */
for (ac = 1; evlog->argv[ac] != NULL; ac++)
bufsize += strlen(evlog->argv[ac]) + 1;
if ((buf = malloc(bufsize)) == NULL)
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
cp = buf;
len = strlcpy(cp, evlog->command, bufsize);
if (len >= bufsize)
sudo_fatalx(U_("internal error, %s overflow"), __func__);
cp += len;
bufsize -= len;
for (ac = 1; evlog->argv[ac] != NULL; ac++) {
if (bufsize < 2)
sudo_fatalx(U_("internal error, %s overflow"), __func__);
*cp++ = ' ';
bufsize--;
len = strlcpy(cp, evlog->argv[ac], bufsize);
if (len >= bufsize)
sudo_fatalx(U_("internal error, %s overflow"), __func__);
cp += len;
bufsize -= len;
}
*newbuf = buf;
debug_return_str(buf);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
expand_command(struct eventlog *evlog, char **newbuf)
{
size_t len, bufsize = strlen(evlog->command) + 1;
char *cp, *buf;
int ac;
debug_decl(expand_command, SUDO_DEBUG_UTIL);
if (evlog->argv == NULL || evlog->argv[0] == NULL || evlog->argv[1] == NULL) {
/* No arguments, we can use the command as-is. */
*newbuf = NULL;
debug_return_str(evlog->command);
}
/* Skip argv[0], we use evlog->command instead. */
for (ac = 1; evlog->argv[ac] != NULL; ac++)
bufsize += strlen(evlog->argv[ac]) + 1;
if ((buf = malloc(bufsize)) == NULL)
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
cp = buf;
len = strlcpy(cp, evlog->command, bufsize);
if (len >= bufsize)
sudo_fatalx(U_("internal error, %s overflow"), __func__);
cp += len;
bufsize -= len;
for (ac = 1; evlog->argv[ac] != NULL; ac++) {
if (bufsize < 2)
sudo_fatalx(U_("internal error, %s overflow"), __func__);
*cp++ = ' ';
bufsize--;
len = strlcpy(cp, evlog->argv[ac], bufsize);
if (len >= bufsize)
sudo_fatalx(U_("internal error, %s overflow"), __func__);
cp += len;
bufsize -= len;
}
*newbuf = buf;
debug_return_str(buf);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
match_expr(struct search_node_list *head, struct eventlog *evlog, bool last_match)
{
struct search_node *sn;
bool res = false, matched = last_match;
char *tofree;
int rc;
debug_decl(match_expr, SUDO_DEBUG_UTIL);
STAILQ_FOREACH(sn, head, entries) {
switch (sn->type) {
case ST_EXPR:
res = match_expr(&sn->u.expr, evlog, matched);
break;
case ST_CWD:
if (evlog->cwd != NULL)
res = strcmp(sn->u.cwd, evlog->cwd) == 0;
break;
case ST_HOST:
if (evlog->submithost != NULL)
res = strcmp(sn->u.host, evlog->submithost) == 0;
break;
case ST_TTY:
if (evlog->ttyname != NULL)
res = strcmp(sn->u.tty, evlog->ttyname) == 0;
break;
case ST_RUNASGROUP:
if (evlog->rungroup != NULL)
res = strcmp(sn->u.runas_group, evlog->rungroup) == 0;
break;
case ST_RUNASUSER:
if (evlog->runuser != NULL)
res = strcmp(sn->u.runas_user, evlog->runuser) == 0;
break;
case ST_USER:
if (evlog->submituser != NULL)
res = strcmp(sn->u.user, evlog->submituser) == 0;
break;
case ST_PATTERN:
rc = regexec(&sn->u.cmdre, expand_command(evlog, &tofree),
0, NULL, 0);
if (rc && rc != REG_NOMATCH) {
char buf[BUFSIZ];
regerror(rc, &sn->u.cmdre, buf, sizeof(buf));
sudo_fatalx("%s", buf);
}
res = rc == REG_NOMATCH ? 0 : 1;
free(tofree);
break;
case ST_FROMDATE:
res = sudo_timespeccmp(&evlog->submit_time, &sn->u.tstamp, >=);
break;
case ST_TODATE:
res = sudo_timespeccmp(&evlog->submit_time, &sn->u.tstamp, <=);
break;
default:
sudo_fatalx(U_("unknown search type %d"), sn->type);
/* NOTREACHED */
}
if (sn->negated)
res = !res;
matched = sn->or ? (res || last_match) : (res && last_match);
last_match = matched;
}
debug_return_bool(matched);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
match_expr(struct search_node_list *head, struct eventlog *evlog, bool last_match)
{
struct search_node *sn;
bool res = false, matched = last_match;
char *tofree;
int rc;
debug_decl(match_expr, SUDO_DEBUG_UTIL);
STAILQ_FOREACH(sn, head, entries) {
switch (sn->type) {
case ST_EXPR:
res = match_expr(&sn->u.expr, evlog, matched);
break;
case ST_CWD:
if (evlog->cwd != NULL)
res = strcmp(sn->u.cwd, evlog->cwd) == 0;
break;
case ST_HOST:
if (evlog->submithost != NULL)
res = strcmp(sn->u.host, evlog->submithost) == 0;
break;
case ST_TTY:
if (evlog->ttyname != NULL)
res = strcmp(sn->u.tty, evlog->ttyname) == 0;
break;
case ST_RUNASGROUP:
if (evlog->rungroup != NULL)
res = strcmp(sn->u.runas_group, evlog->rungroup) == 0;
break;
case ST_RUNASUSER:
if (evlog->runuser != NULL)
res = strcmp(sn->u.runas_user, evlog->runuser) == 0;
break;
case ST_USER:
if (evlog->submituser != NULL)
res = strcmp(sn->u.user, evlog->submituser) == 0;
break;
case ST_PATTERN:
rc = regexec(&sn->u.cmdre, expand_command(evlog, &tofree),
0, NULL, 0);
if (rc && rc != REG_NOMATCH) {
char buf[BUFSIZ];
regerror(rc, &sn->u.cmdre, buf, sizeof(buf));
sudo_fatalx("%s", buf);
}
res = rc == REG_NOMATCH ? 0 : 1;
free(tofree);
break;
case ST_FROMDATE:
res = sudo_timespeccmp(&evlog->submit_time, &sn->u.tstamp, >=);
break;
case ST_TODATE:
res = sudo_timespeccmp(&evlog->submit_time, &sn->u.tstamp, <=);
break;
default:
sudo_fatalx(U_("unknown search type %d"), sn->type);
/* NOTREACHED */
}
if (sn->negated)
res = !res;
matched = sn->or ? (res || last_match) : (res && last_match);
last_match = matched;
}
debug_return_bool(matched);
} | 1 | C | CWE-116 | Improper Encoding or Escaping of Output | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. | https://cwe.mitre.org/data/definitions/116.html | safe |
sudo_passwd_verify(const struct sudoers_context *ctx, struct passwd *pw,
const char *pass, sudo_auth *auth, struct sudo_conv_callback *callback)
{
char des_pass[9], *epass;
char *pw_epasswd = auth->data;
size_t pw_len;
int ret;
debug_decl(sudo_passwd_verify, SUDOERS_DEBUG_AUTH);
/* An empty plain-text password must match an empty encrypted password. */
if (pass[0] == '\0')
debug_return_int(pw_epasswd[0] ? AUTH_FAILURE : AUTH_SUCCESS);
/*
* Truncate to 8 chars if standard DES since not all crypt()'s do this.
*/
pw_len = strlen(pw_epasswd);
if (pw_len == DESLEN || HAS_AGEINFO(pw_epasswd, pw_len)) {
(void)strlcpy(des_pass, pass, sizeof(des_pass));
pass = des_pass;
}
/*
* Normal UN*X password check.
* HP-UX may add aging info (separated by a ',') at the end so
* only compare the first DESLEN characters in that case.
*/
epass = (char *) crypt(pass, pw_epasswd);
ret = AUTH_FAILURE;
if (epass != NULL) {
if (HAS_AGEINFO(pw_epasswd, pw_len) && strlen(epass) == DESLEN) {
if (strncmp(pw_epasswd, epass, DESLEN) == 0)
ret = AUTH_SUCCESS;
} else {
if (strcmp(pw_epasswd, epass) == 0)
ret = AUTH_SUCCESS;
}
}
explicit_bzero(des_pass, sizeof(des_pass));
debug_return_int(ret);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
sudo_auth_cleanup(const struct sudoers_context *ctx, struct passwd *pw,
bool force)
{
sudo_auth *auth;
debug_decl(sudo_auth_cleanup, SUDOERS_DEBUG_AUTH);
/* Call cleanup routines. */
for (auth = auth_switch; auth->name; auth++) {
if (auth->cleanup && !IS_DISABLED(auth)) {
int status = (auth->cleanup)(ctx, pw, auth, force);
if (status != AUTH_SUCCESS) {
/* Assume error msg already printed. */
debug_return_int(-1);
}
}
}
debug_return_int(0);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
sudo_auth_begin_session(const struct sudoers_context *ctx, struct passwd *pw,
char **user_env[])
{
sudo_auth *auth;
int ret = true;
debug_decl(sudo_auth_begin_session, SUDOERS_DEBUG_AUTH);
for (auth = auth_switch; auth->name; auth++) {
if (auth->begin_session && !IS_DISABLED(auth)) {
int status = (auth->begin_session)(ctx, pw, user_env, auth);
switch (status) {
case AUTH_SUCCESS:
break;
case AUTH_FAILURE:
ret = false;
break;
default:
/* Assume error msg already printed. */
ret = -1;
break;
}
}
}
debug_return_int(ret);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
sudo_auth_end_session(void)
{
sudo_auth *auth;
int ret = true;
int status;
debug_decl(sudo_auth_end_session, SUDOERS_DEBUG_AUTH);
for (auth = auth_switch; auth->name; auth++) {
if (auth->end_session && !IS_DISABLED(auth)) {
status = (auth->end_session)(auth);
switch (status) {
case AUTH_SUCCESS:
break;
case AUTH_FAILURE:
ret = false;
break;
default:
/* Assume error msg already printed. */
ret = -1;
break;
}
}
}
debug_return_int(ret);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
sudoers_lookup(struct sudo_nss_list *snl, struct sudoers_context *ctx,
time_t now, sudoers_lookup_callback_fn_t callback, void *cb_data,
int *cmnd_status, int pwflag)
{
struct defaults_list *defs = NULL;
struct sudoers_parse_tree *parse_tree = NULL;
struct cmndspec *cs = NULL;
struct sudo_nss *nss;
struct cmnd_info info;
unsigned int validated = FLAG_NO_USER | FLAG_NO_HOST;
int m, match = UNSPEC;
debug_decl(sudoers_lookup, SUDOERS_DEBUG_PARSER);
/*
* Special case checking the "validate", "list" and "kill" pseudo-commands.
*/
if (pwflag) {
debug_return_uint(sudoers_lookup_pseudo(snl, ctx, now, callback,
cb_data, pwflag));
}
/* Need to be runas user while stat'ing things. */
if (!set_perms(ctx, PERM_RUNAS))
debug_return_uint(validated);
/* Query each sudoers source and check the user. */
TAILQ_FOREACH(nss, snl, entries) {
if (nss->query(ctx, nss, ctx->user.pw) == -1) {
/* The query function should have printed an error message. */
SET(validated, VALIDATE_ERROR);
break;
}
m = sudoers_lookup_check(nss, ctx, &validated, &info, now, callback,
cb_data, &cs, &defs);
if (SPECIFIED(m)) {
match = m;
parse_tree = nss->parse_tree;
}
if (!sudo_nss_can_continue(nss, m))
break;
}
if (SPECIFIED(match)) {
if (info.cmnd_path != NULL) {
/* Update cmnd, cmnd_stat, cmnd_status from matching entry. */
free(ctx->user.cmnd);
ctx->user.cmnd = info.cmnd_path;
if (ctx->user.cmnd_stat != NULL)
*ctx->user.cmnd_stat = info.cmnd_stat;
*cmnd_status = info.status;
}
if (defs != NULL)
(void)update_defaults(ctx, parse_tree, defs, SETDEF_GENERIC, false);
if (!apply_cmndspec(ctx, cs))
SET(validated, VALIDATE_ERROR);
else if (match == ALLOW)
SET(validated, VALIDATE_SUCCESS);
else
SET(validated, VALIDATE_FAILURE);
}
if (!restore_perms())
SET(validated, VALIDATE_ERROR);
debug_return_uint(validated);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
hostlist_matches_int(const struct sudoers_parse_tree *parse_tree,
const struct passwd *pw, const char *lhost, const char *shost,
const struct member_list *list)
{
struct member *m;
int matched = UNSPEC;
debug_decl(hostlist_matches, SUDOERS_DEBUG_MATCH);
TAILQ_FOREACH_REVERSE(m, list, member_list, entries) {
matched = host_matches(parse_tree, pw, lhost, shost, m);
if (SPECIFIED(matched))
break;
}
debug_return_int(matched);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
host_matches(const struct sudoers_parse_tree *parse_tree,
const struct passwd *pw, const char *lhost, const char *shost,
const struct member *m)
{
struct alias *a;
int matched = UNSPEC;
debug_decl(host_matches, SUDOERS_DEBUG_MATCH);
switch (m->type) {
case ALL:
matched = m->negated ? DENY : ALLOW;
break;
case NETGROUP:
if (netgr_matches(parse_tree->nss, m->name, lhost, shost,
def_netgroup_tuple ? pw->pw_name : NULL))
matched = m->negated ? DENY : ALLOW;
break;
case NTWKADDR:
if (addr_matches(m->name))
matched = m->negated ? DENY : ALLOW;
break;
case ALIAS:
a = alias_get(parse_tree, m->name, HOSTALIAS);
if (a != NULL) {
/* XXX */
const int rc = hostlist_matches_int(parse_tree, pw, lhost,
shost, &a->members);
if (SPECIFIED(rc)) {
if (m->negated) {
matched = rc == ALLOW ? DENY : ALLOW;
} else {
matched = rc;
}
}
alias_put(a);
break;
}
FALLTHROUGH;
case WORD:
if (hostname_matches(shost, lhost, m->name))
matched = m->negated ? DENY : ALLOW;
break;
}
sudo_debug_printf(SUDO_DEBUG_DEBUG,
"host %s (%s) matches sudoers host %s%s: %s", lhost, shost,
m->negated ? "!" : "", m->name ? m->name : "ALL",
matched == true ? "true" : "false");
debug_return_int(matched);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
cmnd_matches(const struct sudoers_parse_tree *parse_tree,
const struct member *m, const char *runchroot, struct cmnd_info *info)
{
struct alias *a;
struct sudo_command *c;
int rc, matched = UNSPEC;
debug_decl(cmnd_matches, SUDOERS_DEBUG_MATCH);
switch (m->type) {
case ALL:
case COMMAND:
c = (struct sudo_command *)m->name;
if (command_matches(parse_tree->ctx, c->cmnd, c->args, runchroot,
info, &c->digests))
matched = m->negated ? DENY : ALLOW;
break;
case ALIAS:
a = alias_get(parse_tree, m->name, CMNDALIAS);
if (a != NULL) {
rc = cmndlist_matches(parse_tree, &a->members, runchroot, info);
if (SPECIFIED(rc)) {
if (m->negated) {
matched = rc == ALLOW ? DENY : ALLOW;
} else {
matched = rc;
}
}
alias_put(a);
}
break;
}
debug_return_int(matched);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
cmndlist_matches(const struct sudoers_parse_tree *parse_tree,
const struct member_list *list, const char *runchroot,
struct cmnd_info *info)
{
struct member *m;
int matched = UNSPEC;
debug_decl(cmndlist_matches, SUDOERS_DEBUG_MATCH);
TAILQ_FOREACH_REVERSE(m, list, member_list, entries) {
matched = cmnd_matches(parse_tree, m, runchroot, info);
if (SPECIFIED(matched))
break;
}
debug_return_int(matched);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
user_matches(const struct sudoers_parse_tree *parse_tree,
const struct passwd *pw, const struct member *m)
{
const struct sudoers_context *ctx = parse_tree->ctx;
const char *lhost = parse_tree->lhost ? parse_tree->lhost : ctx->runas.host;
const char *shost = parse_tree->shost ? parse_tree->shost : ctx->runas.shost;
int matched = UNSPEC;
struct alias *a;
debug_decl(user_matches, SUDOERS_DEBUG_MATCH);
switch (m->type) {
case ALL:
matched = m->negated ? DENY : ALLOW;
break;
case NETGROUP:
if (netgr_matches(parse_tree->nss, m->name,
def_netgroup_tuple ? lhost : NULL,
def_netgroup_tuple ? shost : NULL, pw->pw_name))
matched = m->negated ? DENY : ALLOW;
break;
case USERGROUP:
if (usergr_matches(m->name, pw->pw_name, pw))
matched = m->negated ? DENY : ALLOW;
break;
case ALIAS:
if ((a = alias_get(parse_tree, m->name, USERALIAS)) != NULL) {
/* XXX */
const int rc = userlist_matches(parse_tree, pw, &a->members);
if (SPECIFIED(rc)) {
if (m->negated) {
matched = rc == ALLOW ? DENY : ALLOW;
} else {
matched = rc;
}
}
alias_put(a);
break;
}
FALLTHROUGH;
case WORD:
if (userpw_matches(m->name, pw->pw_name, pw))
matched = m->negated ? DENY : ALLOW;
break;
}
debug_return_int(matched);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
cmnd_matches_all(const struct sudoers_parse_tree *parse_tree,
const struct member *m, const char *runchroot, struct cmnd_info *info)
{
const bool negated = m->negated;
struct sudo_command *c;
int matched = UNSPEC;
struct alias *a;
debug_decl(cmnd_matches_all, SUDOERS_DEBUG_MATCH);
switch (m->type) {
case ALL:
c = (struct sudo_command *)m->name;
if (command_matches(parse_tree->ctx, c->cmnd, c->args, runchroot,
info, &c->digests))
matched = negated ? DENY : ALLOW;
break;
case ALIAS:
a = alias_get(parse_tree, m->name, CMNDALIAS);
if (a != NULL) {
TAILQ_FOREACH_REVERSE(m, &a->members, member_list, entries) {
matched = cmnd_matches_all(parse_tree, m, runchroot, info);
if (SPECIFIED(matched)) {
if (negated)
matched = matched == ALLOW ? DENY : ALLOW;
break;
}
}
alias_put(a);
}
break;
}
debug_return_int(matched);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
runas_grouplist_matches(const struct sudoers_parse_tree *parse_tree,
const struct member_list *group_list, struct member **matching_group)
{
const struct sudoers_context *ctx = parse_tree->ctx;
int group_matched = UNSPEC;
struct member *m;
struct alias *a;
debug_decl(runas_grouplist_matches, SUDOERS_DEBUG_MATCH);
if (group_list != NULL) {
TAILQ_FOREACH_REVERSE(m, group_list, member_list, entries) {
switch (m->type) {
case ALL:
group_matched = m->negated ? DENY : ALLOW;
break;
case ALIAS:
a = alias_get(parse_tree, m->name, RUNASALIAS);
if (a != NULL) {
const int rc = runas_grouplist_matches(parse_tree,
&a->members, matching_group);
if (SPECIFIED(rc)) {
if (m->negated) {
group_matched = rc == ALLOW ? DENY : ALLOW;
} else {
group_matched = rc;
}
}
alias_put(a);
break;
}
FALLTHROUGH;
case WORD:
if (group_matches(m->name, ctx->runas.gr))
group_matched = m->negated ? DENY : ALLOW;
break;
}
if (SPECIFIED(group_matched)) {
if (matching_group != NULL && m->type != ALIAS)
*matching_group = m;
break;
}
}
}
if (!SPECIFIED(group_matched)) {
struct gid_list *runas_groups;
/*
* The runas group was not explicitly allowed by sudoers.
* Check whether it is one of the target user's groups.
*/
if (ctx->runas.pw->pw_gid == ctx->runas.gr->gr_gid) {
group_matched = ALLOW; /* runas group matches passwd db */
} else if ((runas_groups = runas_getgroups(ctx)) != NULL) {
int i;
for (i = 0; i < runas_groups->ngids; i++) {
if (runas_groups->gids[i] == ctx->runas.gr->gr_gid) {
group_matched = ALLOW; /* matched aux group vector */
break;
}
}
sudo_gidlist_delref(runas_groups);
}
}
debug_return_int(group_matched);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
userlist_matches(const struct sudoers_parse_tree *parse_tree,
const struct passwd *pw, const struct member_list *list)
{
struct member *m;
int matched = UNSPEC;
debug_decl(userlist_matches, SUDOERS_DEBUG_MATCH);
TAILQ_FOREACH_REVERSE(m, list, member_list, entries) {
matched = user_matches(parse_tree, pw, m);
if (SPECIFIED(matched))
break;
}
debug_return_int(matched);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
static int parse_packet(const char *payload, struct ncrx_msg *msg)
{
char buf[1024];
char *p, *tok;
int idx;
memset(msg, 0, sizeof(*msg));
p = strchr(payload, ';');
if (!p || p - payload >= (signed)sizeof(buf))
goto einval;
memcpy(buf, payload, p - payload);
buf[p - payload] = '\0';
msg->text = p + 1;
msg->text_len = strlen(msg->text);
if (msg->text_len > NCRX_LINE_MAX)
msg->text_len = NCRX_LINE_MAX;
/* <level>,<sequnum>,<timestamp>,<contflag>[,KEY=VAL]* */
idx = 0;
p = buf;
while ((tok = strsep(&p, ","))) {
char *endp, *key, *val;
unsigned long long v;
switch (idx++) {
case 0:
v = strtoul(tok, &endp, 0);
if (*endp != '\0' || v > UINT8_MAX)
goto einval;
msg->facility = v >> 3;
msg->level = v & ((1 << 3) - 1);
continue;
case 1:
v = strtoull(tok, &endp, 0);
if (*endp != '\0')
goto einval;
msg->seq = v;
continue;
case 2:
v = strtoull(tok, &endp, 0);
if (*endp != '\0')
goto einval;
msg->ts_usec = v;
continue;
case 3:
if (tok[0] == 'c')
msg->cont_start = 1;
else if (tok[0] == '+')
msg->cont = 1;
continue;
}
val = tok;
key = strsep(&val, "=");
if (!val)
continue;
if (!strcmp(key, "ncfrag")) {
unsigned nf_off, nf_len;
if (sscanf(val, "%u/%u", &nf_off, &nf_len) != 2)
goto einval;
if (!msg->text_len ||
nf_len >= NCRX_LINE_MAX ||
nf_off >= nf_len ||
nf_off + msg->text_len > nf_len)
goto einval;
msg->ncfrag_off = nf_off;
msg->ncfrag_len = msg->text_len;
msg->ncfrag_left = nf_len - msg->ncfrag_len;
msg->text_len = nf_len;
} else if (!strcmp(key, "ncemg")) {
v = strtoul(val, &endp, 0);
if (*endp != '\0')
goto einval;
msg->emg = v;
}
}
return 0;
einval:
errno = EINVAL;
return -1;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
int valid_field (const char *field, const char *illegal)
{
const char *cp;
int err = 0;
if (NULL == field) {
return -1;
}
/* For each character of field, search if it appears in the list
* of illegal characters. */
for (cp = field; '\0' != *cp; cp++) {
if (strchr (illegal, *cp) != NULL) {
err = -1;
break;
}
}
if (0 == err) {
/* Search if there are non-printable or control characters */
for (cp = field; '\0' != *cp; cp++) {
if (!isprint (*cp)) {
err = 1;
}
if (!iscntrl (*cp)) {
err = -1;
break;
}
}
}
return err;
} | 1 | C | CWE-74 | Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection') | The product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/74.html | safe |
static u32 crc32sum(u32 crc, u8 * RESTRICT buf, size_t size) {
// Test endianness. The code needs to be different for LE and BE systems.
u32 test = 1;
if (*(u8 *) &test) {
while (size--) crc = crc32Table[(crc ^ *(buf++)) & 0xff] ^ (crc >> 8);
return crc;
} else {
while (size--) crc = crc32Table[((crc >> 24) ^ *(buf++)) & 0xff] ^ (crc << 8);
return crc;
}
} | 1 | C | CWE-125 | Out-of-bounds Read | The product reads data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/125.html | safe |
static int mrled(u8 * RESTRICT in, u8 * RESTRICT out, s32 outlen, s32 maxin) {
s32 op = 0, ip = 0;
s32 c, pc = -1;
s32 t[256] = { 0 };
s32 run = 0;
if(maxin < 32)
return 1;
for (s32 i = 0; i < 32; ++i) {
c = in[ip++];
for (s32 j = 0; j < 8; ++j) t[i * 8 + j] = (c >> j) & 1;
}
while (op < outlen && ip < maxin) {
c = in[ip++];
if (t[c]) {
for (run = 0; (pc = in[ip++]) == 255 && ip < maxin; run += 255)
;
run += pc + 1;
for (; run > 0 && op < outlen; --run) out[op++] = c;
} else
out[op++] = c;
}
return op != outlen;
} | 1 | C | CWE-125 | Out-of-bounds Read | The product reads data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/125.html | safe |
BZIP3_API struct bz3_state * bz3_new(s32 block_size) {
if (block_size < KiB(65) || block_size > MiB(511)) {
return NULL;
}
struct bz3_state * bz3_state = malloc(sizeof(struct bz3_state));
if (!bz3_state) {
return NULL;
}
bz3_state->cm_state = malloc(sizeof(state));
bz3_state->swap_buffer = malloc(bz3_bound(block_size));
bz3_state->sais_array = malloc(BWT_BOUND(block_size) * sizeof(s32));
memset(bz3_state->sais_array, 0, sizeof(s32) * BWT_BOUND(block_size));
bz3_state->lzp_lut = calloc(1 << LZP_DICTIONARY, sizeof(s32));
if (!bz3_state->cm_state || !bz3_state->swap_buffer || !bz3_state->sais_array || !bz3_state->lzp_lut) {
if (bz3_state->cm_state) free(bz3_state->cm_state);
if (bz3_state->swap_buffer) free(bz3_state->swap_buffer);
if (bz3_state->sais_array) free(bz3_state->sais_array);
if (bz3_state->lzp_lut) free(bz3_state->lzp_lut);
free(bz3_state);
return NULL;
}
bz3_state->block_size = block_size;
bz3_state->last_error = BZ3_OK;
return bz3_state;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
int dns_HTTPS_add_ipv4hint(struct dns_rr_nested *svcparam, unsigned char *addr[], int addr_num)
{
if (_dns_left_len(&svcparam->context) < 4 + addr_num * DNS_RR_A_LEN) {
return -1;
}
unsigned short value = DNS_HTTPS_T_IPV4HINT;
dns_add_rr_nested_memcpy(svcparam, &value, 2);
value = addr_num * DNS_RR_A_LEN;
dns_add_rr_nested_memcpy(svcparam, &value, 2);
for (int i = 0; i < addr_num; i++) {
dns_add_rr_nested_memcpy(svcparam, addr[i], DNS_RR_A_LEN);
}
return 0;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
int dns_add_rr_nested_end(struct dns_rr_nested *rr_nested, dns_type_t rtype)
{
if (rr_nested == NULL || rr_nested->rr_start == NULL) {
return -1;
}
int len = rr_nested->context.ptr - rr_nested->rr_start;
unsigned char *ptr = rr_nested->rr_len_ptr;
if (ptr == NULL || _dns_left_len(&rr_nested->context) < 2) {
return -1;
}
/* NO SVC keys, reset ptr */
if (len <= 14) {
rr_nested->context.ptr = rr_nested->rr_start;
return 0;
}
_dns_write_short(&ptr, len - rr_nested->rr_head_len);
return _dns_rr_add_end(rr_nested->context.packet, rr_nested->type, rtype, len);
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
int dns_add_rr_nested_memcpy(struct dns_rr_nested *rr_nested, const void *data, int data_len)
{
if (rr_nested == NULL || data == NULL || data_len <= 0) {
return -1;
}
if (_dns_left_len(&rr_nested->context) < data_len) {
return -1;
}
memcpy(rr_nested->context.ptr, data, data_len);
rr_nested->context.ptr += data_len;
return 0;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
int dns_get_HTTPS_svcparm_start(struct dns_rrs *rrs, struct dns_https_param **https_param, char *domain, int maxsize,
int *ttl, int *priority, char *target, int target_size)
{
int qtype = 0;
unsigned char *data = NULL;
int rr_len = 0;
data = dns_get_rr_nested_start(rrs, domain, maxsize, &qtype, ttl, &rr_len);
if (data == NULL) {
return -1;
}
if (qtype != DNS_T_HTTPS) {
return -1;
}
if (rr_len < 2) {
return -1;
}
*priority = _dns_read_short(&data);
rr_len -= 2;
if (rr_len <= 0) {
return -1;
}
int len = strnlen((char *)data, rr_len);
safe_strncpy(target, (char *)data, target_size);
data += len + 1;
rr_len -= len + 1;
if (rr_len < 0) {
return -1;
}
if (rr_len == 0) {
*https_param = NULL;
return 0;
}
*https_param = (struct dns_https_param *)data;
return 0;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
int dns_HTTPS_add_ipv6hint(struct dns_rr_nested *svcparam, unsigned char *addr[], int addr_num)
{
if (_dns_left_len(&svcparam->context) < 4 + addr_num * DNS_RR_AAAA_LEN) {
return -1;
}
unsigned short value = DNS_HTTPS_T_IPV6HINT;
dns_add_rr_nested_memcpy(svcparam, &value, 2);
value = addr_num * DNS_RR_AAAA_LEN;
dns_add_rr_nested_memcpy(svcparam, &value, 2);
for (int i = 0; i < addr_num; i++) {
dns_add_rr_nested_memcpy(svcparam, addr[i], DNS_RR_AAAA_LEN);
}
return 0;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
static int _dns_encode_HTTPS(struct dns_context *context, struct dns_rrs *rrs)
{
int ret = 0;
int qtype = 0;
int qclass = 0;
char domain[DNS_MAX_CNAME_LEN];
char target[DNS_MAX_CNAME_LEN] = {0};
unsigned char *rr_len_ptr = NULL;
unsigned char *start = NULL;
unsigned char *rr_start = NULL;
int ttl = 0;
int priority = 0;
struct dns_https_param *param = NULL;
ret =
dns_get_HTTPS_svcparm_start(rrs, ¶m, domain, DNS_MAX_CNAME_LEN, &ttl, &priority, target, DNS_MAX_CNAME_LEN);
if (ret < 0) {
tlog(TLOG_DEBUG, "get https param failed.");
return 0;
}
qtype = DNS_T_HTTPS;
qclass = DNS_C_IN;
ret = _dns_encode_rr_head(context, domain, qtype, qclass, ttl, 0, &rr_len_ptr);
if (ret < 0) {
return -1;
}
rr_start = context->ptr;
if (_dns_left_len(context) < 2) {
tlog(TLOG_ERROR, "left len is invalid.");
return -1;
}
_dns_write_short(&context->ptr, priority);
ret = _dns_encode_domain(context, target);
if (ret < 0) {
return -1;
}
start = context->ptr;
for (; param != NULL; param = dns_get_HTTPS_svcparm_next(rrs, param)) {
if (context->ptr - start > rrs->len || _dns_left_len(context) <= 0) {
return -1;
}
if (param->len + 4 > _dns_left_len(context)) {
return -1;
}
_dns_write_short(&context->ptr, param->key);
_dns_write_short(&context->ptr, param->len);
switch (param->key) {
case DNS_HTTPS_T_MANDATORY:
case DNS_HTTPS_T_NO_DEFAULT_ALPN:
case DNS_HTTPS_T_ALPN:
case DNS_HTTPS_T_PORT:
case DNS_HTTPS_T_IPV4HINT:
case DNS_HTTPS_T_ECH:
case DNS_HTTPS_T_IPV6HINT: {
memcpy(context->ptr, param->value, param->len);
context->ptr += param->len;
} break;
default:
/* skip unknown key */
context->ptr -= 4;
break;
}
}
if (_dns_left_len(context) < 2) {
return -1;
}
_dns_write_short(&rr_len_ptr, context->ptr - rr_start);
return 0;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
int dns_add_HTTPS_start(struct dns_rr_nested *svcparam_buffer, struct dns_packet *packet, dns_rr_type type,
const char *domain, int ttl, int priority, const char *target)
{
svcparam_buffer = dns_add_rr_nested_start(svcparam_buffer, packet, type, DNS_T_HTTPS, domain, ttl);
if (svcparam_buffer == NULL) {
return -1;
}
int target_len = 0;
if (target == NULL) {
target = "";
}
target_len = strnlen(target, DNS_MAX_CNAME_LEN) + 1;
if (_dns_left_len(&svcparam_buffer->context) < 2 + target_len) {
return -1;
}
/* add rr data */
_dns_write_short(&svcparam_buffer->context.ptr, priority);
safe_strncpy((char *)svcparam_buffer->context.ptr, target, target_len);
svcparam_buffer->context.ptr += target_len;
return 0;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
static int _dns_encode_domain(struct dns_context *context, const char *domain)
{
int num = 0;
int total_len = 0;
unsigned char *ptr_num = context->ptr++;
int dict_offset = 0;
dict_offset = _dns_get_domain_offset(context, domain);
total_len++;
/*[len]string[len]string...[0]0 */
while (_dns_left_len(context) > 1 && *domain != 0) {
total_len++;
if (dict_offset >= 0) {
int offset = 0xc000 | dict_offset;
if (_dns_left_len(context) < 2) {
return -1;
}
_dns_write_short(&ptr_num, offset);
context->ptr++;
ptr_num = NULL;
return total_len;
}
if (*domain == '.') {
*ptr_num = num;
num = 0;
ptr_num = context->ptr;
domain++;
context->ptr++;
dict_offset = _dns_get_domain_offset(context, domain);
continue;
}
*context->ptr = *domain;
num++;
context->ptr++;
domain++;
}
if (_dns_left_len(context) < 1) {
return -1;
}
*ptr_num = num;
if (total_len > 1) {
/* if domain is '\0', [domain] is '\0' */
*(context->ptr) = 0;
total_len++;
context->ptr++;
}
if (_dns_left_len(context) <= 0) {
return -1;
}
return total_len;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
int dns_HTTPS_add_alpn(struct dns_rr_nested *svcparam, const char *alpn, int alpn_len)
{
if (_dns_left_len(&svcparam->context) < 2 + 2 + alpn_len) {
return -1;
}
unsigned short value = DNS_HTTPS_T_ALPN;
dns_add_rr_nested_memcpy(svcparam, &value, 2);
value = alpn_len;
dns_add_rr_nested_memcpy(svcparam, &value, 2);
dns_add_rr_nested_memcpy(svcparam, alpn, alpn_len);
return 0;
} | 1 | C | CWE-787 | Out-of-bounds Write | The product writes data past the end, or before the beginning, of the intended buffer. | https://cwe.mitre.org/data/definitions/787.html | safe |
PrintBackend *cpdbCreateBackendFromFile(GDBusConnection *connection,
const char *backend_file_name)
{
FILE *file = NULL;
PrintBackend *proxy;
GError *error = NULL;
char *path, *backend_name;
const char *info_dir_name;
char obj_path[CPDB_BSIZE];
backend_name = cpdbGetStringCopy(backend_file_name);
if ((info_dir_name = getenv("CPDB_BACKEND_INFO_DIR")) == NULL)
info_dir_name = CPDB_BACKEND_INFO_DIR;
path = cpdbConcatPath(info_dir_name, backend_file_name);
if ((file = fopen(path, "r")) == NULL)
{
logerror("Error creating backend %s : Couldn't open %s for reading\n",
backend_name, path);
free(path);
return NULL;
}
if (fscanf(file, "%1023s", obj_path) == 0)
{
logerror("Error creating backend %s : Couldn't parse %s\n",
backend_name, path);
free(path);
fclose(file);
return NULL;
}
free(path);
fclose(file);
proxy = print_backend_proxy_new_sync(connection,
0,
backend_name,
obj_path,
NULL,
&error);
if (error)
{
logerror("Error creating backend proxy for %s : %s\n",
backend_name, error->message);
return NULL;
}
return proxy;
} | 1 | C | CWE-121 | Stack-based Buffer Overflow | A stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function). | https://cwe.mitre.org/data/definitions/121.html | safe |
ssl3_free(SSL *s)
{
if (s == NULL)
return;
tls1_cleanup_key_block(s);
ssl3_release_read_buffer(s);
ssl3_release_write_buffer(s);
tls_content_free(s->s3->rcontent);
tls_buffer_free(s->s3->alert_fragment);
tls_buffer_free(s->s3->handshake_fragment);
freezero(s->s3->hs.sigalgs, s->s3->hs.sigalgs_len);
sk_X509_pop_free(s->s3->hs.peer_certs, X509_free);
sk_X509_pop_free(s->s3->hs.peer_certs_no_leaf, X509_free);
tls_key_share_free(s->s3->hs.key_share);
tls13_secrets_destroy(s->s3->hs.tls13.secrets);
freezero(s->s3->hs.tls13.cookie, s->s3->hs.tls13.cookie_len);
tls13_clienthello_hash_clear(&s->s3->hs.tls13);
tls_buffer_free(s->s3->hs.tls13.quic_read_buffer);
sk_X509_NAME_pop_free(s->s3->hs.tls12.ca_names, X509_NAME_free);
sk_X509_pop_free(s->verified_chain, X509_free);
s->verified_chain = NULL;
tls1_transcript_free(s);
tls1_transcript_hash_free(s);
free(s->s3->alpn_selected);
freezero(s->s3->peer_quic_transport_params,
s->s3->peer_quic_transport_params_len);
freezero(s->s3, sizeof(*s->s3));
s->s3 = NULL;
} | 1 | C | CWE-415 | Double Free | The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations. | https://cwe.mitre.org/data/definitions/415.html | safe |
ssl3_free(SSL *s)
{
if (s == NULL)
return;
tls1_cleanup_key_block(s);
ssl3_release_read_buffer(s);
ssl3_release_write_buffer(s);
tls_content_free(s->s3->rcontent);
tls_buffer_free(s->s3->alert_fragment);
tls_buffer_free(s->s3->handshake_fragment);
freezero(s->s3->hs.sigalgs, s->s3->hs.sigalgs_len);
sk_X509_pop_free(s->s3->hs.peer_certs, X509_free);
sk_X509_pop_free(s->s3->hs.peer_certs_no_leaf, X509_free);
tls_key_share_free(s->s3->hs.key_share);
tls13_secrets_destroy(s->s3->hs.tls13.secrets);
freezero(s->s3->hs.tls13.cookie, s->s3->hs.tls13.cookie_len);
tls13_clienthello_hash_clear(&s->s3->hs.tls13);
tls_buffer_free(s->s3->hs.tls13.quic_read_buffer);
sk_X509_NAME_pop_free(s->s3->hs.tls12.ca_names, X509_NAME_free);
sk_X509_pop_free(s->verified_chain, X509_free);
s->verified_chain = NULL;
tls1_transcript_free(s);
tls1_transcript_hash_free(s);
free(s->s3->alpn_selected);
freezero(s->s3->peer_quic_transport_params,
s->s3->peer_quic_transport_params_len);
freezero(s->s3, sizeof(*s->s3));
s->s3 = NULL;
} | 1 | C | CWE-416 | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. | https://cwe.mitre.org/data/definitions/416.html | safe |
int pico_tcp_initconn(struct pico_socket *s)
{
struct pico_socket_tcp *ts = TCP_SOCK(s);
struct pico_frame *syn;
struct pico_tcp_hdr *hdr;
uint16_t mtu, opt_len = tcp_options_size(ts, PICO_TCP_SYN);
syn = s->net->alloc(s->stack, s->net, NULL, (uint16_t)(PICO_SIZE_TCPHDR + opt_len));
if (!syn)
return -1;
hdr = (struct pico_tcp_hdr *) syn->transport_hdr;
if (!ts->snd_nxt)
ts->snd_nxt = long_be(pico_paws());
ts->snd_last = ts->snd_nxt;
ts->cwnd = PICO_TCP_IW;
mtu = (uint16_t)pico_socket_get_mss(s);
if (mtu > PICO_SIZE_TCPHDR + PICO_TCP_MIN_MSS)
ts->mss = (uint16_t)(mtu - PICO_SIZE_TCPHDR);
else
ts->mss = PICO_TCP_MIN_MSS;
ts->ssthresh = (uint16_t)((uint16_t)(PICO_DEFAULT_SOCKETQ / ts->mss) - (((uint16_t)(PICO_DEFAULT_SOCKETQ / ts->mss)) >> 3u));
syn->sock = s;
hdr->seq = long_be(ts->snd_nxt);
hdr->len = (uint8_t)((PICO_SIZE_TCPHDR + opt_len) << 2);
hdr->flags = PICO_TCP_SYN;
tcp_set_space(ts);
hdr->rwnd = short_be(ts->wnd);
tcp_add_options(ts, syn, PICO_TCP_SYN, opt_len);
hdr->trans.sport = ts->sock.local_port;
hdr->trans.dport = ts->sock.remote_port;
hdr->crc = 0;
hdr->crc = short_be(pico_tcp_checksum(syn));
/* TCP: ENQUEUE to PROTO ( SYN ) */
tcp_dbg("Sending SYN... (ports: %d - %d) size: %d\n", short_be(ts->sock.local_port), short_be(ts->sock.remote_port), syn->buffer_len);
ts->retrans_tmr = pico_timer_add(s->stack, PICO_TCP_SYN_TO << ts->backoff, initconn_retry, ts);
if (!ts->retrans_tmr) {
tcp_dbg("TCP: Failed to start initconn_retry timer\n");
PICO_FREE(syn);
return -1;
}
pico_enqueue(&s->stack->q_tcp.out, syn);
return 0;
} | 1 | C | CWE-908 | Use of Uninitialized Resource | The product uses or accesses a resource that has not been initialized. | https://cwe.mitre.org/data/definitions/908.html | safe |
struct pico_socket *pico_tcp_open(struct pico_stack *S, uint16_t family)
{
struct pico_socket_tcp *t = PICO_ZALLOC(sizeof(struct pico_socket_tcp));
if (!t)
return NULL;
t->sock.stack = S;
t->sock.timestamp = TCP_TIME;
pico_socket_set_family(&t->sock, family);
t->mss = (uint16_t)(pico_socket_get_mss(&t->sock));
if (t->mss > PICO_SIZE_TCPHDR + PICO_TCP_MIN_MSS)
t->mss -= (uint16_t)PICO_SIZE_TCPHDR;
else
t->mss = PICO_TCP_MIN_MSS;
t->tcpq_in.pool.root = t->tcpq_hold.pool.root = t->tcpq_out.pool.root = &LEAF;
t->tcpq_hold.pool.compare = t->tcpq_out.pool.compare = segment_compare;
t->tcpq_in.pool.compare = input_segment_compare;
t->tcpq_in.max_size = PICO_DEFAULT_SOCKETQ;
t->tcpq_out.max_size = PICO_DEFAULT_SOCKETQ;
t->tcpq_hold.max_size = 2u * t->mss;
rto_set(t, PICO_TCP_RTO_MIN);
/* Uncomment next line and disable Nagle by default */
t->sock.opt_flags |= (1 << PICO_SOCKET_OPT_TCPNODELAY);
/* Uncomment next line and Nagle is enabled by default */
/* t->sock.opt_flags &= (uint16_t) ~(1 << PICO_SOCKET_OPT_TCPNODELAY); */
/* Set default linger for the socket */
t->linger_timeout = PICO_SOCKET_LINGER_TIMEOUT;
#ifdef PICO_TCP_SUPPORT_SOCKET_STATS
if (!pico_timer_add(t->sock.stack, 2000, sock_stats, t)) {
tcp_dbg("TCP: Failed to start socket statistics timer\n");
PICO_FREE(t);
return NULL;
}
#endif
t->keepalive_tmr = pico_timer_add(t->sock.stack, 1000, pico_tcp_keepalive, t);
if (!t->keepalive_tmr) {
tcp_dbg("TCP: Failed to start keepalive timer\n");
PICO_FREE(t);
return NULL;
}
tcp_set_space(t);
return &t->sock;
} | 1 | C | CWE-908 | Use of Uninitialized Resource | The product uses or accesses a resource that has not been initialized. | https://cwe.mitre.org/data/definitions/908.html | safe |
int ipfilter(struct pico_frame *f)
{
struct filter_node temp;
struct pico_ipv4_hdr *ipv4_hdr = (struct pico_ipv4_hdr *) f->net_hdr;
struct pico_trans *trans;
struct pico_icmp4_hdr *icmp_hdr;
memset(&temp, 0u, sizeof(struct filter_node));
temp.fdev = f->dev;
temp.out_addr = ipv4_hdr->dst.addr;
temp.in_addr = ipv4_hdr->src.addr;
if ((f->transport_hdr + sizeof(struct pico_trans)) <= (f->buffer + f->buffer_len)) {
if ((ipv4_hdr->proto == PICO_PROTO_TCP) || (ipv4_hdr->proto == PICO_PROTO_UDP)) {
trans = (struct pico_trans *) f->transport_hdr;
temp.out_port = short_be(trans->dport);
temp.in_port = short_be(trans->sport);
} else if(ipv4_hdr->proto == PICO_PROTO_ICMP4) {
icmp_hdr = (struct pico_icmp4_hdr *) f->transport_hdr;
if(icmp_hdr->type == PICO_ICMP_UNREACH && icmp_hdr->code == PICO_ICMP_UNREACH_FILTER_PROHIB)
return 0;
}
temp.proto = ipv4_hdr->proto;
}
temp.priority = f->priority;
temp.tos = ipv4_hdr->tos;
return ipfilter_apply_filter(f, &temp);
} | 1 | C | NVD-CWE-noinfo | null | null | null | safe |
static inline void tcp_parse_option_mss(struct pico_socket_tcp *t, uint8_t len, uint8_t *opt, uint32_t *idx)
{
uint16_t mss;
if (tcpopt_len_check(idx, len, PICO_TCPOPTLEN_MSS) < 0)
return;
if ((*idx + PICO_TCPOPTLEN_MSS) > len)
return;
t->mss_ok = 1;
mss = short_from(opt + *idx);
*idx += (uint32_t)sizeof(uint16_t);
if (t->mss > short_be(mss))
t->mss = short_be(mss);
} | 1 | C | CWE-754 | Improper Check for Unusual or Exceptional Conditions | The product does not check or incorrectly checks for unusual or exceptional conditions that are not expected to occur frequently during day to day operation of the product. | https://cwe.mitre.org/data/definitions/754.html | safe |
static int tcp_parse_options(struct pico_frame *f)
{
struct pico_socket_tcp *t = (struct pico_socket_tcp *)f->sock;
uint8_t *opt = f->transport_hdr + PICO_SIZE_TCPHDR;
uint32_t i = 0;
f->timestamp = 0;
if (f->buffer + f->buffer_len > f->transport_hdr + f->transport_len)
return -1;
while (i < (f->transport_len - PICO_SIZE_TCPHDR)) {
uint8_t type = opt[i++];
uint8_t len;
if(i < (f->transport_len - PICO_SIZE_TCPHDR) && (type > 1))
len = opt[i++];
else
len = 1;
if (f->payload && ((opt + i) > f->payload))
break;
if (len == 0) {
return -1;
}
tcp_dbg_options("Received option '%d', len = %d \n", type, len);
switch (type) {
case PICO_TCP_OPTION_NOOP:
case PICO_TCP_OPTION_END:
break;
case PICO_TCP_OPTION_WS:
tcp_parse_option_ws(t, len, opt, &i);
break;
case PICO_TCP_OPTION_SACK_OK:
tcp_parse_option_sack_ok(t, f, len, &i);
break;
case PICO_TCP_OPTION_MSS:
tcp_parse_option_mss(t, len, opt, &i);
break;
case PICO_TCP_OPTION_TIMESTAMP:
tcp_parse_option_timestamp(t, f, len, opt, &i);
break;
case PICO_TCP_OPTION_SACK:
tcp_rcv_sack(t, opt + i, len - 2);
i = i + len - 2;
break;
default:
tcp_dbg_options("TCP: received unsupported option %u\n", type);
i = i + len - 2;
}
}
return 0;
} | 1 | C | CWE-754 | Improper Check for Unusual or Exceptional Conditions | The product does not check or incorrectly checks for unusual or exceptional conditions that are not expected to occur frequently during day to day operation of the product. | https://cwe.mitre.org/data/definitions/754.html | safe |
_xdr_kadm5_principal_ent_rec(XDR *xdrs, kadm5_principal_ent_rec *objp,
int v)
{
unsigned int n;
bool_t r;
if (!xdr_krb5_principal(xdrs, &objp->principal)) {
return (FALSE);
}
if (!xdr_krb5_timestamp(xdrs, &objp->princ_expire_time)) {
return (FALSE);
}
if (!xdr_krb5_timestamp(xdrs, &objp->last_pwd_change)) {
return (FALSE);
}
if (!xdr_krb5_timestamp(xdrs, &objp->pw_expiration)) {
return (FALSE);
}
if (!xdr_krb5_deltat(xdrs, &objp->max_life)) {
return (FALSE);
}
if (!xdr_nulltype(xdrs, (void **) &objp->mod_name,
xdr_krb5_principal)) {
return (FALSE);
}
if (!xdr_krb5_timestamp(xdrs, &objp->mod_date)) {
return (FALSE);
}
if (!xdr_krb5_flags(xdrs, &objp->attributes)) {
return (FALSE);
}
if (!xdr_krb5_kvno(xdrs, &objp->kvno)) {
return (FALSE);
}
if (!xdr_krb5_kvno(xdrs, &objp->mkvno)) {
return (FALSE);
}
if (!xdr_nullstring(xdrs, &objp->policy)) {
return (FALSE);
}
if (!xdr_long(xdrs, &objp->aux_attributes)) {
return (FALSE);
}
if (!xdr_krb5_deltat(xdrs, &objp->max_renewable_life)) {
return (FALSE);
}
if (!xdr_krb5_timestamp(xdrs, &objp->last_success)) {
return (FALSE);
}
if (!xdr_krb5_timestamp(xdrs, &objp->last_failed)) {
return (FALSE);
}
if (!xdr_krb5_kvno(xdrs, &objp->fail_auth_count)) {
return (FALSE);
}
if (!xdr_krb5_int16(xdrs, &objp->n_key_data)) {
return (FALSE);
}
if (xdrs->x_op == XDR_DECODE && objp->n_key_data < 0) {
return (FALSE);
}
if (!xdr_krb5_int16(xdrs, &objp->n_tl_data)) {
return (FALSE);
}
if (!xdr_nulltype(xdrs, (void **) &objp->tl_data,
xdr_krb5_tl_data)) {
return FALSE;
}
n = objp->n_key_data;
r = xdr_array(xdrs, (caddr_t *) &objp->key_data, &n, objp->n_key_data,
sizeof(krb5_key_data), xdr_krb5_key_data_nocontents);
objp->n_key_data = n;
if (!r) {
return (FALSE);
}
return (TRUE);
} | 1 | C | CWE-824 | Access of Uninitialized Pointer | The product accesses or uses a pointer that has not been initialized. | https://cwe.mitre.org/data/definitions/824.html | safe |
DltReturnValue dlt_file_message(DltFile *file, int index, int verbose)
{
PRINT_FUNCTION_VERBOSE(verbose);
if (file == NULL)
return DLT_RETURN_WRONG_PARAMETER;
/* check if message is in range */
if (index < 0 || index >= file->counter) {
dlt_vlog(LOG_WARNING, "Message %d out of range!\r\n", index);
return DLT_RETURN_WRONG_PARAMETER;
}
/* seek to position in file */
if (fseek(file->handle, file->index[index], SEEK_SET) != 0) {
dlt_vlog(LOG_WARNING, "Seek to message %d to position %ld failed!\r\n",
index, file->index[index]);
return DLT_RETURN_ERROR;
}
/* read all header and payload */
if (dlt_file_read_header(file, verbose) < DLT_RETURN_OK)
return DLT_RETURN_ERROR;
if (dlt_file_read_header_extended(file, verbose) < DLT_RETURN_OK)
return DLT_RETURN_ERROR;
if (dlt_file_read_data(file, verbose) < DLT_RETURN_OK)
return DLT_RETURN_ERROR;
/* set current position in file */
file->position = index;
return DLT_RETURN_OK;
} | 1 | C | CWE-120 | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | https://cwe.mitre.org/data/definitions/120.html | safe |
static int benaloh(void) {
int code = RLC_ERR;
bdpe_t pub, prv;
bn_t a, b;
dig_t in, out;
uint8_t buf[RLC_BN_BITS / 8 + 1];
size_t len;
int result;
dig_t prime = 0xFB;
bn_null(a);
bn_null(b);
bdpe_null(pub);
bdpe_null(prv);
RLC_TRY {
bn_new(a);
bn_new(b);
bdpe_new(pub);
bdpe_new(prv);
result = cp_bdpe_gen(pub, prv, prime, RLC_BN_BITS);
TEST_CASE("benaloh encryption/decryption is correct") {
TEST_ASSERT(result == RLC_OK, end);
len = RLC_BN_BITS / 8 + 1;
rand_bytes(buf, 1);
in = buf[0] % prime;
TEST_ASSERT(cp_bdpe_enc(buf, &len, in, pub) == RLC_OK, end);
TEST_ASSERT(cp_bdpe_dec(&out, buf, len, prv) == RLC_OK, end);
TEST_ASSERT(in == out, end);
} TEST_END;
TEST_CASE("benaloh encryption/decryption is homomorphic") {
TEST_ASSERT(result == RLC_OK, end);
len = RLC_BN_BITS / 8 + 1;
rand_bytes(buf, 1);
in = buf[0] % prime;
TEST_ASSERT(cp_bdpe_enc(buf, &len, in, pub) == RLC_OK, end);
bn_read_bin(a, buf, len);
rand_bytes(buf, 1);
out = (buf[0] % prime);
in = (in + out) % prime;
TEST_ASSERT(cp_bdpe_enc(buf, &len, out, pub) == RLC_OK, end);
bn_read_bin(b, buf, len);
bn_mul(a, a, b);
bn_mod(a, a, pub->n);
len = bn_size_bin(pub->n);
bn_write_bin(buf, len, a);
TEST_ASSERT(cp_bdpe_dec(&out, buf, len, prv) == RLC_OK, end);
TEST_ASSERT(in == out, end);
} TEST_END;
} RLC_CATCH_ANY {
RLC_ERROR(end);
}
code = RLC_OK;
end:
bn_free(a);
bn_free(b);
bdpe_free(pub);
bdpe_free(prv);
return code;
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
static void benaloh(void) {
bdpe_t pub, prv;
dig_t in, new;
uint8_t out[RLC_BN_BITS / 8 + 1];
size_t out_len;
dig_t prime = 0xFB;
bdpe_null(pub);
bdpe_null(prv);
bdpe_new(pub);
bdpe_new(prv);
BENCH_ONE("cp_bdpe_gen", cp_bdpe_gen(pub, prv, prime, RLC_BN_BITS), 1);
BENCH_RUN("cp_bdpe_enc") {
out_len = RLC_BN_BITS / 8 + 1;
rand_bytes(out, 1);
in = out[0] % prime;
BENCH_ADD(cp_bdpe_enc(out, &out_len, in, pub));
cp_bdpe_dec(&new, out, out_len, prv);
} BENCH_END;
BENCH_RUN("cp_bdpe_dec") {
out_len = RLC_BN_BITS / 8 + 1;
rand_bytes(out, 1);
in = out[0] % prime;
cp_bdpe_enc(out, &out_len, in, pub);
BENCH_ADD(cp_bdpe_dec(&new, out, out_len, prv));
} BENCH_END;
bdpe_free(pub);
bdpe_free(prv);
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
static void memory2(void) {
ep2_t a[BENCH];
BENCH_FEW("ep2_null", ep2_null(a[i]), 1);
BENCH_FEW("ep2_new", ep2_new(a[i]), 1);
for (int i = 0; i < BENCH; i++) {
ep2_free(a[i]);
}
for (int i = 0; i < BENCH; i++) {
ep2_new(a[i]);
}
BENCH_FEW("ep2_free", ep2_free(a[i]), 1);
(void)a;
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_grow(bn_t a, size_t digits) {
#if ALLOC == DYNAMIC
dig_t *t;
if (a->alloc < digits) {
/* At least add RLC_BN_SIZE more digits. */
digits += (RLC_BN_SIZE * 2) - (digits % RLC_BN_SIZE);
t = (dig_t *)realloc(a->dp, (RLC_DIG / 8) * digits);
if (t == NULL) {
RLC_THROW(ERR_NO_MEMORY);
return;
}
a->dp = t;
/* Set the newly allocated digits to zero. */
a->alloc = digits;
}
#elif ALLOC == AUTO
if (digits > RLC_BN_SIZE) {
RLC_THROW(ERR_NO_PRECI);
return;
}
(void)a;
#endif
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_make(bn_t a, size_t digits) {
if (digits < 0) {
RLC_THROW(ERR_NO_VALID);
}
/* Allocate at least one digit. */
digits = RLC_MAX(digits, 1);
#if ALLOC == DYNAMIC
if (digits % RLC_BN_SIZE != 0) {
/* Pad the number of digits to a multiple of the block. */
digits += (RLC_BN_SIZE - digits % RLC_BN_SIZE);
}
if (a != NULL) {
a->dp = NULL;
#if ALIGN == 1
a->dp = (dig_t *)malloc(digits * sizeof(dig_t));
#elif OPSYS == WINDOWS
a->dp = _aligned_malloc(digits * sizeof(dig_t), ALIGN);
#else
int r = posix_memalign((void **)&a->dp, ALIGN, digits * sizeof(dig_t));
if (r == ENOMEM) {
RLC_THROW(ERR_NO_MEMORY);
}
if (r == EINVAL) {
RLC_THROW(ERR_NO_VALID);
}
#endif /* ALIGN */
}
if (a->dp == NULL) {
free((void *)a);
RLC_THROW(ERR_NO_MEMORY);
}
#else
/* Verify if the number of digits is sane. */
if (digits > RLC_BN_SIZE) {
RLC_THROW(ERR_NO_PRECI);
return;
} else {
digits = RLC_BN_SIZE;
}
#endif
if (a != NULL) {
a->used = 1;
a->dp[0] = 0;
a->alloc = digits;
a->sign = RLC_POS;
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_trim(bn_t a) {
if (a->used <= a->alloc) {
while (a->used > 0 && a->dp[a->used - 1] == 0) {
--(a->used);
}
/* Zero can't be negative. */
if (a->used == 0) {
a->used = 1;
a->dp[0] = 0;
a->sign = RLC_POS;
}
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_mxp_slide(bn_t c, const bn_t a, const bn_t b, const bn_t m) {
bn_t tab[RLC_TABLE_SIZE], t, u, r;
size_t l, w = 1;
uint8_t *win = RLC_ALLOCA(uint8_t, bn_bits(b));
if (win == NULL) {
RLC_THROW(ERR_NO_MEMORY);
return;
}
if (bn_cmp_dig(m, 1) == RLC_EQ) {
RLC_FREE(win);
bn_zero(c);
return;
}
if (bn_is_zero(b)) {
RLC_FREE(win);
bn_set_dig(c, 1);
return;
}
bn_null(t);
bn_null(u);
bn_null(r);
/* Initialize table. */
for (size_t i = 0; i < RLC_TABLE_SIZE; i++) {
bn_null(tab[i]);
}
/* Find window size. */
l = bn_bits(b);
if (l <= 21) {
w = 2;
} else if (l <= 32) {
w = 3;
} else if (l <= 128) {
w = 4;
} else if (l <= 256) {
w = 5;
} else if (l <= 512) {
w = 6;
} else {
w = 7;
}
RLC_TRY {
for (size_t i = 0; i < (1 << (w - 1)); i++) {
bn_new(tab[i]);
}
bn_new(t);
bn_new(u);
bn_new(r);
bn_mod_pre(u, m);
#if BN_MOD == MONTY
bn_set_dig(r, 1);
bn_mod_monty_conv(r, r, m);
bn_mod_monty_conv(t, a, m);
#else /* BN_MOD == BARRT || BN_MOD == RADIX */
bn_set_dig(r, 1);
bn_copy(t, a);
#endif
bn_copy(tab[0], t);
bn_sqr(t, tab[0]);
bn_mod(t, t, m, u);
/* Create table. */
for (size_t i = 1; i < 1 << (w - 1); i++) {
bn_mul(tab[i], tab[i - 1], t);
bn_mod(tab[i], tab[i], m, u);
}
bn_rec_slw(win, &l, b, w);
for (size_t i = 0; i < l; i++) {
if (win[i] == 0) {
bn_sqr(r, r);
bn_mod(r, r, m, u);
} else {
for (size_t j = 0; j < util_bits_dig(win[i]); j++) {
bn_sqr(r, r);
bn_mod(r, r, m, u);
}
bn_mul(r, r, tab[win[i] >> 1]);
bn_mod(r, r, m, u);
}
}
bn_trim(r);
#if BN_MOD == MONTY
bn_mod_monty_back(r, r, m);
#endif
if (bn_sign(b) == RLC_NEG) {
bn_mod_inv(c, r, m);
} else {
bn_copy(c, r);
}
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
RLC_FINALLY {
for (size_t i = 0; i < (1 << (w - 1)); i++) {
bn_free(tab[i]);
}
bn_free(u);
bn_free(t);
bn_free(r);
RLC_FREE(win);
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_gen_prime_safep(bn_t a, size_t bits) {
while (1) {
do {
bn_rand(a, RLC_POS, bits);
} while (bn_bits(a) != bits);
/* Check if (a - 1)/2 is prime. */
bn_sub_dig(a, a, 1);
bn_rsh(a, a, 1);
if (bn_is_prime(a)) {
/* Restore a. */
bn_lsh(a, a, 1);
bn_add_dig(a, a, 1);
if (bn_is_prime(a)) {
/* Should be prime now. */
return;
}
}
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
int bn_gen_prime_factor(bn_t a, bn_t b, size_t abits, size_t bbits) {
bn_t t;
int result = RLC_OK;
if (! (bbits>abits) ) {
return RLC_ERR;
}
bn_null(t);
RLC_TRY {
bn_new(t);
bn_gen_prime(a, abits);
do {
bn_rand(t, RLC_POS, bbits - bn_bits(a));
do {
bn_mul(b, a, t);
bn_add_dig(b, b, 1);
bn_add_dig(t, t, 1);
} while(! bn_is_prime(b));
} while (bn_bits(b) != bbits);
}
RLC_CATCH_ANY {
result = RLC_ERR;
}
RLC_FINALLY {
bn_free(t);
}
return result;
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_gen_prime_stron(bn_t a, size_t bits) {
dig_t i, j;
int found, k;
bn_t r, s, t;
bn_null(r);
bn_null(s);
bn_null(t);
RLC_TRY {
bn_new(r);
bn_new(s);
bn_new(t);
do {
do {
/* Generate two large primes r and s. */
bn_rand(s, RLC_POS, bits / 2 - RLC_DIG / 2);
bn_rand(t, RLC_POS, bits / 2 - RLC_DIG / 2);
} while (!bn_is_prime(s) || !bn_is_prime(t));
found = 1;
bn_rand(a, RLC_POS, bits / 2 - bn_bits(t) - 1);
i = a->dp[0];
bn_dbl(t, t);
do {
/* Find first prime r = 2 * i * t + 1. */
bn_mul_dig(r, t, i);
bn_add_dig(r, r, 1);
i++;
if (bn_bits(r) > bits / 2 - 1) {
found = 0;
break;
}
} while (!bn_is_prime(r));
if (found == 0) {
continue;
}
/* Compute t = 2 * (s^(r-2) mod r) * s - 1. */
bn_sub_dig(t, r, 2);
#if BN_MOD != PMERS
bn_mxp(t, s, t, r);
#else
bn_exp(t, s, t, r);
#endif
bn_mul(t, t, s);
bn_dbl(t, t);
bn_sub_dig(t, t, 1);
k = bits - bn_bits(r);
k -= bn_bits(s);
bn_rand(a, RLC_POS, k);
j = a->dp[0];
do {
/* Find first prime a = t + 2 * j * r * s. */
bn_mul(a, r, s);
bn_mul_dig(a, a, j);
bn_dbl(a, a);
bn_add(a, a, t);
j++;
if (bn_bits(a) > bits) {
found = 0;
break;
}
} while (!bn_is_prime(a));
} while (found == 0 && bn_bits(a) != bits);
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
RLC_FINALLY {
bn_free(r);
bn_free(s);
bn_free(t);
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_gen_prime_basic(bn_t a, size_t bits) {
while (1) {
do {
bn_rand(a, RLC_POS, bits);
} while (bn_bits(a) != bits);
if (bn_is_prime(a)) {
return;
}
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
static char get_bits(const bn_t a, size_t from, size_t to) {
int f, t;
dig_t mf, mt;
RLC_RIP(from, f, from);
RLC_RIP(to, t, to);
if (f == t) {
/* Same digit. */
mf = RLC_MASK(from);
if (to + 1 >= RLC_DIG) {
mt = RLC_DMASK;
} else {
mt = RLC_MASK(to + 1);
}
mf = mf ^ mt;
return ((a->dp[f] & (mf)) >> from);
} else {
mf = RLC_MASK(RLC_DIG - from) << from;
mt = RLC_MASK(to + 1);
return ((a->dp[f] & mf) >> from) |
((a->dp[t] & mt) << (RLC_DIG - from));
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_rec_naf(int8_t *naf, size_t *len, const bn_t k, size_t w) {
int i, l;
bn_t t;
dig_t t0, mask;
int8_t u_i;
if (*len < (bn_bits(k) + 1)) {
*len = 0;
RLC_THROW(ERR_NO_BUFFER);
return;
}
bn_null(t);
RLC_TRY {
bn_new(t);
bn_abs(t, k);
mask = RLC_MASK(w);
l = (1 << w);
memset(naf, 0, *len);
i = 0;
if (w == 2) {
while (!bn_is_zero(t)) {
if (!bn_is_even(t)) {
bn_get_dig(&t0, t);
u_i = 2 - (t0 & mask);
if (u_i < 0) {
bn_add_dig(t, t, -u_i);
} else {
bn_sub_dig(t, t, u_i);
}
*naf = u_i;
} else {
*naf = 0;
}
bn_hlv(t, t);
i++;
naf++;
}
} else {
while (!bn_is_zero(t)) {
if (!bn_is_even(t)) {
bn_get_dig(&t0, t);
u_i = t0 & mask;
if (u_i > l / 2) {
u_i = (int8_t)(u_i - l);
}
if (u_i < 0) {
bn_add_dig(t, t, -u_i);
} else {
bn_sub_dig(t, t, u_i);
}
*naf = u_i;
} else {
*naf = 0;
}
bn_hlv(t, t);
i++;
naf++;
}
}
*len = i;
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
RLC_FINALLY {
bn_free(t);
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_rec_slw(uint8_t *win, size_t *len, const bn_t k, size_t w) {
int i, j, l, s;
l = bn_bits(k);
if (*len < l) {
*len = 0;
RLC_THROW(ERR_NO_BUFFER);
return;
}
memset(win, 0, *len);
i = l - 1;
j = 0;
while (i >= 0) {
if (!bn_get_bit(k, i)) {
i--;
win[j++] = 0;
} else {
s = RLC_MAX(i - w + 1, 0);
while (!bn_get_bit(k, s)) {
s++;
}
win[j++] = get_bits(k, s, i);
i = s - 1;
}
}
*len = j;
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_rec_glv(bn_t k0, bn_t k1, const bn_t k, const bn_t n, const bn_t *v1,
const bn_t *v2) {
bn_t t, b1, b2;
int r1, r2;
size_t bits;
bn_null(b1);
bn_null(b2);
bn_null(t);
RLC_TRY {
bn_new(b1);
bn_new(b2);
bn_new(t);
bn_abs(t, k);
bits = bn_bits(n);
bn_mul(b1, t, v1[0]);
r1 = bn_get_bit(b1, bits);
bn_rsh(b1, b1, bits + 1);
bn_add_dig(b1, b1, r1);
bn_mul(b2, t, v2[0]);
r2 = bn_get_bit(b2, bits);
bn_rsh(b2, b2, bits + 1);
bn_add_dig(b2, b2, r2);
bn_mul(k0, b1, v1[1]);
bn_mul(k1, b2, v2[1]);
bn_add(k0, k0, k1);
bn_sub(k0, t, k0);
bn_mul(k1, b1, v1[2]);
bn_mul(t, b2, v2[2]);
bn_add(k1, k1, t);
bn_neg(k1, k1);
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
RLC_FINALLY {
bn_free(b1);
bn_free(b2);
bn_free(t);
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_rec_tnaf_mod(bn_t r0, bn_t r1, const bn_t k, int u, size_t m) {
bn_t t, t0, t1, t2, t3;
bn_null(t);
bn_null(t0);
bn_null(t1);
bn_null(t2);
bn_null(t3);
RLC_TRY {
bn_new(t);
bn_new(t0);
bn_new(t1);
bn_new(t2);
bn_new(t3);
/* (a0, a1) = (1, 0). */
bn_set_dig(t0, 1);
bn_zero(t1);
/* (b0, b1) = (0, 0). */
bn_zero(t2);
bn_zero(t3);
/* (r0, r1) = (k, 0). */
bn_abs(r0, k);
bn_zero(r1);
for (int i = 0; i < m; i++) {
if (!bn_is_even(r0)) {
/* r0 = r0 - 1. */
bn_sub_dig(r0, r0, 1);
/* (b0, b1) = (b0 + a0, b1 + a1). */
bn_add(t2, t2, t0);
bn_add(t3, t3, t1);
}
bn_hlv(t, r0);
/* r0 = r1 + mu * r0 / 2. */
if (u == -1) {
bn_sub(r0, r1, t);
} else {
bn_add(r0, r1, t);
}
/* r1 = - r0 / 2. */
bn_neg(r1, t);
bn_dbl(t, t1);
/* a1 = a0 + mu * a1. */
if (u == -1) {
bn_sub(t1, t0, t1);
} else {
bn_add(t1, t0, t1);
}
/* a0 = - 2 * a1. */
bn_neg(t0, t);
}
/*r 0 = r0 + b0, r1 = r1 + b1. */
bn_add(r0, r0, t2);
bn_add(r1, r1, t3);
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
RLC_FINALLY {
bn_free(t);
bn_free(t0);
bn_free(t1);
bn_free(t2);
bn_free(t3);
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_rec_win(uint8_t *win, size_t *len, const bn_t k, size_t w) {
int i, j, l;
l = bn_bits(k);
if (*len < RLC_CEIL(l, w)) {
*len = 0;
RLC_THROW(ERR_NO_BUFFER);
return;
}
memset(win, 0, *len);
j = 0;
for (i = 0; i < l - w; i += w) {
win[j++] = get_bits(k, i, i + w - 1);
}
win[j++] = get_bits(k, i, bn_bits(k) - 1);
*len = j;
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_rec_reg(int8_t *naf, size_t *len, const bn_t k, size_t n, size_t w) {
int i, l;
bn_t t;
dig_t t0, mask;
int8_t u_i;
bn_null(t);
mask = RLC_MASK(w);
l = RLC_CEIL(n, w - 1);
if (*len <= l) {
*len = 0;
RLC_THROW(ERR_NO_BUFFER);
return;
}
RLC_TRY {
bn_new(t);
bn_abs(t, k);
memset(naf, 0, *len);
i = 0;
if (w == 2) {
for (i = 0; i < l; i++) {
u_i = (t->dp[0] & mask) - 2;
t->dp[0] -= u_i;
naf[i] = u_i;
bn_hlv(t, t);
}
bn_get_dig(&t0, t);
naf[i] = t0;
} else {
for (i = 0; i < l; i++) {
u_i = (t->dp[0] & mask) - (1 << (w - 1));
t->dp[0] -= u_i;
naf[i] = u_i;
bn_rsh(t, t, w - 1);
}
bn_get_dig(&t0, t);
naf[i] = t0;
}
*len = l + 1;
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
RLC_FINALLY {
bn_free(t);
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_rec_jsf(int8_t *jsf, size_t *len, const bn_t k, const bn_t l) {
bn_t n0, n1;
dig_t l0, l1;
int8_t u0, u1, d0, d1;
int i, j, offset;
if (*len < (2 * bn_bits(k) + 1)) {
*len = 0;
RLC_THROW(ERR_NO_BUFFER);
return;
}
bn_null(n0);
bn_null(n1);
RLC_TRY {
bn_new(n0);
bn_new(n1);
bn_abs(n0, k);
bn_abs(n1, l);
i = bn_bits(k);
j = bn_bits(l);
offset = RLC_MAX(i, j) + 1;
memset(jsf, 0, *len);
i = 0;
d0 = d1 = 0;
while (!(bn_is_zero(n0) && d0 == 0) || !(bn_is_zero(n1) && d1 == 0)) {
bn_get_dig(&l0, n0);
bn_get_dig(&l1, n1);
/* For reduction modulo 8. */
l0 = (l0 + d0) & RLC_MASK(3);
l1 = (l1 + d1) & RLC_MASK(3);
if (l0 % 2 == 0) {
u0 = 0;
} else {
u0 = 2 - (l0 & RLC_MASK(2));
if ((l0 == 3 || l0 == 5) && ((l1 & RLC_MASK(2)) == 2)) {
u0 = (int8_t)-u0;
}
}
jsf[i] = u0;
if (l1 % 2 == 0) {
u1 = 0;
} else {
u1 = 2 - (l1 & RLC_MASK(2));
if ((l1 == 3 || l1 == 5) && ((l0 & RLC_MASK(2)) == 2)) {
u1 = (int8_t)-u1;
}
}
jsf[i + offset] = u1;
if (d0 + d0 == 1 + u0) {
d0 = (int8_t)(1 - d0);
}
if (d1 + d1 == 1 + u1) {
d1 = (int8_t)(1 - d1);
}
i++;
bn_hlv(n0, n0);
bn_hlv(n1, n1);
}
*len = i;
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
RLC_FINALLY {
bn_free(n0);
bn_free(n1);
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_lsh(bn_t c, const bn_t a, unsigned int bits) {
int digits;
dig_t carry;
bn_copy(c, a);
RLC_RIP(bits, digits, bits);
RLC_TRY {
bn_grow(c, c->used + digits + (bits > 0));
c->used = a->used + digits;
c->sign = a->sign;
if (digits > 0) {
dv_lshd(c->dp, a->dp, c->used, digits);
}
if (bits > 0) {
if (c != a) {
carry = bn_lshb_low(c->dp + digits, a->dp, a->used, bits);
} else {
carry = bn_lshb_low(c->dp + digits, c->dp + digits, c->used - digits, bits);
}
if (carry != 0) {
c->dp[c->used] = carry;
(c->used)++;
}
}
bn_trim(c);
} RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_rsh(bn_t c, const bn_t a, unsigned int bits) {
int digits = 0;
bn_copy(c, a);
RLC_RIP(bits, digits, bits);
if (digits > 0) {
dv_rshd(c->dp, a->dp, a->used, digits);
}
if (a->used > digits) {
c->used = a->used - digits;
} else {
c->used = 0;
}
c->sign = a->sign;
if (c->used > 0 && bits > 0) {
if (digits == 0 && c != a) {
bn_rshb_low(c->dp, a->dp + digits, a->used - digits, bits);
} else {
bn_rshb_low(c->dp, c->dp, c->used, bits);
}
}
bn_trim(c);
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
int bn_smb_jac(const bn_t a, const bn_t b) {
bn_t t0, t1, r;
int t, h, res;
bn_null(t0);
bn_null(t1);
bn_null(r);
/* Argument b must be odd. */
if (bn_is_even(b) || bn_sign(b) == RLC_NEG) {
RLC_THROW(ERR_NO_VALID);
return 0;
}
RLC_TRY {
bn_new(t0);
bn_new(t1);
bn_new(r);
t = 1;
if (bn_sign(a) == RLC_NEG) {
bn_add(t0, a, b);
} else {
bn_copy(t0, a);
}
bn_copy(t1, b);
while (1) {
/* t0 = a mod b. */
bn_mod(t0, t0, t1);
/* If a = 0 then if n = 1 return t else return 0. */
if (bn_is_zero(t0)) {
if (bn_cmp_dig(t1, 1) == RLC_EQ) {
res = 1;
if (t == -1) {
res = -1;
}
break;
} else {
res = 0;
break;
}
}
/* Write t0 as 2^h * t0. */
h = 0;
while (bn_is_even(t0) && !bn_is_zero(t0)) {
h++;
bn_rsh(t0, t0, 1);
}
/* If h != 0 (mod 2) and n != +-1 (mod 8) then t = -t. */
bn_mod_2b(r, t1, 3);
if ((h % 2 != 0) && (bn_cmp_dig(r, 1) != RLC_EQ) &&
(bn_cmp_dig(r, 7) != RLC_EQ)) {
t = -t;
}
/* If t0 != 1 (mod 4) and n != 1 (mod 4) then t = -t. */
bn_mod_2b(r, t0, 2);
if (bn_cmp_dig(r, 1) != RLC_EQ) {
bn_mod_2b(r, t1, 2);
if (bn_cmp_dig(r, 1) != RLC_EQ) {
t = -t;
}
}
bn_copy(r, t0);
bn_copy(t0, t1);
bn_copy(t1, r);
}
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
RLC_FINALLY {
bn_free(t0);
bn_free(t1);
bn_free(r);
}
return res;
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_srt(bn_t c, bn_t a) {
bn_t h, l, m, t;
size_t bits;
int cmp;
if (bn_sign(a) == RLC_NEG) {
RLC_THROW(ERR_NO_VALID);
}
bits = bn_bits(a);
bits += (bits % 2);
bn_null(h);
bn_null(l);
bn_null(m);
bn_null(t);
RLC_TRY {
bn_new(h);
bn_new(l);
bn_new(m);
bn_new(t);
bn_zero(l);
bn_set_2b(h, bits >> 1);
if (bits >= 2) {
bn_set_2b(l, (bits >> 1) - 1);
}
/* Trivial binary search approach. */
do {
bn_add(m, h, l);
bn_hlv(m, m);
bn_sqr(t, m);
cmp = bn_cmp(t, a);
bn_sub(t, h, l);
if (cmp == RLC_GT) {
bn_copy(h, m);
} else if (cmp == RLC_LT) {
bn_copy(l, m);
}
} while (bn_cmp_dig(t, 1) == RLC_GT && cmp != RLC_EQ);
bn_copy(c, m);
}
RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
RLC_FINALLY {
bn_free(h);
bn_free(l);
bn_free(m);
bn_free(t);
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
size_t bn_bits(const bn_t a) {
int bits;
if (bn_is_zero(a)) {
return 0;
}
/* Bits in lower digits. */
bits = (a->used - 1) * RLC_DIG;
return bits + util_bits_dig(a->dp[a->used - 1]);
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_write_raw(dig_t *raw, size_t len, const bn_t a) {
int i, size;
size = a->used;
if (len < size) {
RLC_THROW(ERR_NO_BUFFER);
return;
}
for (i = 0; i < size; i++) {
raw[i] = a->dp[i];
}
for (; i < len; i++) {
raw[i] = 0;
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_set_2b(bn_t a, size_t b) {
int i, d;
if (b >= RLC_BN_SIZE * RLC_DIG) {
RLC_THROW(ERR_NO_VALID);
} else {
RLC_RIP(b, d, b);
bn_grow(a, d + 1);
for (i = 0; i < d; i++) {
a->dp[i] = 0;
}
a->used = d + 1;
a->dp[d] = ((dig_t)1 << b);
a->sign = RLC_POS;
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_read_raw(bn_t a, const dig_t *raw, size_t len) {
RLC_TRY {
bn_grow(a, len);
a->used = len;
a->sign = RLC_POS;
dv_copy(a->dp, raw, len);
bn_trim(a);
} RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
size_t bn_size_raw(const bn_t a) {
return a->used;
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
size_t bn_size_str(const bn_t a, unsigned int radix) {
int digits = 0;
bn_t t;
bn_null(t);
/* Check the radix. */
if (radix < 2 || radix > 64) {
RLC_THROW(ERR_NO_VALID);
return 0;
}
if (bn_is_zero(a)) {
return 2;
}
/* Binary case requires the bits, a sign and the null terminator. */
if (radix == 2) {
return bn_bits(a) + (a->sign == RLC_NEG ? 1 : 0) + 1;
}
if (a->sign == RLC_NEG) {
digits++;
}
RLC_TRY {
bn_new(t);
bn_copy(t, a);
t->sign = RLC_POS;
while (!bn_is_zero(t)) {
bn_div_dig(t, t, (dig_t)radix);
digits++;
}
} RLC_CATCH_ANY {
RLC_THROW(ERR_CAUGHT);
} RLC_FINALLY {
bn_free(t);
}
return digits + 1;
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
void bn_set_bit(bn_t a, size_t bit, int value) {
int d;
if (bit < 0) {
RLC_THROW(ERR_NO_VALID);
return;
}
RLC_RIP(bit, d, bit);
bn_grow(a, d);
if (value == 1) {
a->dp[d] |= ((dig_t)1 << bit);
if ((d + 1) > a->used) {
a->used = d + 1;
}
} else {
a->dp[d] &= ~((dig_t)1 << bit);
bn_trim(a);
}
} | 1 | C | CWE-190 | Integer Overflow or Wraparound | The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | https://cwe.mitre.org/data/definitions/190.html | safe |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.