Changeset d7d3267
- Timestamp:
- 11/29/18 13:37:20 (2 years ago)
- Branches:
- develop
- Children:
- 50e9c6b
- Parents:
- 54642da (diff), fdf23b8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 41 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/combiner_ordered.c
ree6e802 r2193905 36 36 static int init_combiner(libtrace_t *t, libtrace_combine_t *c) { 37 37 int i = 0; 38 assert(trace_get_perpkt_threads(t) > 0); 38 if (trace_get_perpkt_threads(t) <= 0) { 39 trace_set_err(t, TRACE_ERR_INIT_FAILED, "You must have atleast 1 processing thread"); 40 return -1; 41 } 39 42 libtrace_queue_t *queues; 40 43 c->queues = calloc(sizeof(libtrace_queue_t), trace_get_perpkt_threads(t)); … … 245 248 246 249 for (i = 0; i < trace_get_perpkt_threads(trace); i++) { 247 assert(libtrace_deque_get_size(&queues[i]) == 0); 250 if (libtrace_deque_get_size(&queues[i]) != 0) { 251 trace_set_err(trace, TRACE_ERR_COMBINER, 252 "Failed to destroy queues, A thread still has data in destroy()"); 253 return; 254 } 248 255 } 249 256 free(queues); -
lib/combiner_sorted.c
ree6e802 r2193905 34 34 static int init_combiner(libtrace_t *t, libtrace_combine_t *c) { 35 35 int i = 0; 36 assert(trace_get_perpkt_threads(t) > 0); 36 if (trace_get_perpkt_threads(t) <= 0) { 37 trace_set_err(t, TRACE_ERR_INIT_FAILED, "You must have atleast 1 processing thread"); 38 return -1; 39 } 37 40 libtrace_vector_t *queues; 38 41 c->queues = calloc(sizeof(libtrace_vector_t), trace_get_perpkt_threads(t)); … … 105 108 106 109 for (i = 0; i < trace_get_perpkt_threads(trace); i++) { 107 assert(libtrace_vector_get_size(&queues[i]) == 0); 110 if (libtrace_vector_get_size(&queues[i]) != 0) { 111 trace_set_err(trace, TRACE_ERR_COMBINER, 112 "Failed to destroy queues, A thread still has data in destroy()"); 113 return; 114 } 108 115 libtrace_vector_destroy(&queues[i]); 109 116 } -
lib/combiner_unordered.c
ree6e802 r2193905 34 34 static int init_combiner(libtrace_t *t, libtrace_combine_t *c) { 35 35 int i = 0; 36 assert(trace_get_perpkt_threads(t) > 0); 36 if (trace_get_perpkt_threads(t) <= 0) { 37 trace_set_err(t, TRACE_ERR_INIT_FAILED, "You must have atleast 1 processing thread"); 38 return -1; 39 } 37 40 libtrace_queue_t *queues; 38 41 c->queues = calloc(sizeof(libtrace_queue_t), trace_get_perpkt_threads(t)); … … 87 90 88 91 for (i = 0; i < trace_get_perpkt_threads(trace); i++) { 89 assert(libtrace_deque_get_size(&queues[i]) == 0); 92 if (libtrace_deque_get_size(&queues[i]) != 0) { 93 trace_set_err(trace, TRACE_ERR_COMBINER, 94 "Failed to destroy queues, A thread still has data in destroy()"); 95 return; 96 } 90 97 } 91 98 free(queues); -
lib/data-struct/buckets.c
ree6e802 r2193905 26 26 27 27 #include <stdlib.h> 28 #include <assert.h>29 28 #include <string.h> 30 29 #include "buckets.h" … … 183 182 libtrace_bucket_node_t tmp; 184 183 185 assert(id != 0); 184 if (id == 0) { 185 fprintf(stderr, "bucket ID cannot be 0 in libtrace_release_bucket_id()\n"); 186 return; 187 } 186 188 187 189 pthread_mutex_lock(&b->lock); 188 190 bnode = b->packets[id]; 189 assert(bnode != NULL); 191 if (!bnode) { 192 fprintf(stderr, "bucket ID %lu is NULL in libtrace_release_bucket_id()\n", id); 193 return; 194 } 190 195 191 196 … … 196 201 s = id - bnode->startindex; 197 202 } 198 assert(s < bnode->slots); 199 assert(bnode->released[s] != 0); 203 if (s >= bnode->slots) { 204 fprintf(stderr, "Error in libtrace_release_bucket_id()\n"); 205 return; 206 } 207 if (bnode->released[s] == 0) { 208 fprintf(stderr, "Error in libtrace_release_bucket_id()\n"); 209 return; 210 } 200 211 201 212 … … 228 239 break; 229 240 230 assert(lnode->next != NULL); 241 if (!lnode->next) { 242 fprintf(stderr, "Error in libtrace_release_bucket_id()\n"); 243 return; 244 } 231 245 for (i = 0; i < front->slots; i++) { 232 246 if (front->released[i] == 2) { -
lib/data-struct/deque.c
ree6e802 r2193905 63 63 ASSERT_RET(pthread_mutex_lock(&q->lock), == 0); 64 64 if (q->head == NULL) { 65 assert(q->tail == NULL && q->size == 0); 65 if (q->tail != NULL || q->size != 0) { 66 fprintf(stderr, "Error deque head cannot be NULL with a non NULL tail and size of more than 0 in libtrace_deque_push_back()\n"); 67 return; 68 } 66 69 new_node->prev = NULL; 67 70 q->head = q->tail = new_node; 68 71 } else { 69 assert (q->tail != NULL); 72 if (q->tail == NULL) { 73 fprintf(stderr, "Error deque tail cannot be NULL if it contains a head in libtrace_deque_push_back()\n"); 74 return; 75 } 70 76 q->tail->next = new_node; 71 77 new_node->prev = q->tail; // Done the double link … … 86 92 ASSERT_RET(pthread_mutex_lock(&q->lock), == 0); 87 93 if (q->head == NULL) { 88 assert(q->tail == NULL && q->size == 0); 94 if (q->tail != NULL || q->size != 0) { 95 fprintf(stderr, "Error deque head cannot be NULL with a non NULL tail and size of more than 0 in libtrace_deque_push_front()\n"); 96 return; 97 } 89 98 new_node->next = NULL; 90 99 q->head = q->tail = new_node; 91 100 } else { 92 assert (q->head != NULL);93 101 q->head->prev = new_node; 94 102 new_node->next = q->head; // Done the double link -
lib/data-struct/linked_list.c
ree6e802 r2193905 26 26 #include "linked_list.h" 27 27 28 #include <assert.h>29 28 #include <stddef.h> 30 29 #include <stdlib.h> … … 72 71 /* Create the new node */ 73 72 new = (libtrace_list_node_t *)malloc(sizeof(libtrace_list_node_t)); 74 assert(new != NULL); 73 if (!new) { 74 fprintf(stderr, "Unable to allocate memory for node in libtrace_list_push_front()\n"); 75 return; 76 } 75 77 new->data = malloc(l->element_size); 76 assert(new->data != NULL); 78 if (!new->data) { 79 fprintf(stderr, "Unable to allocate memory for node data in libtrace_list_push_front()\n"); 80 } 77 81 78 82 new->prev = NULL; … … 80 84 81 85 if (l->head == NULL) { 82 assert(l->tail == NULL && l->size == 0); 86 if (l->tail != NULL || l->size != 0) { 87 fprintf(stderr, "Error cannot have a NULL head with a non NULL tail and a size of non 0 in libtrace_list_push_front()\n"); 88 return; 89 } 83 90 new->next = NULL; 84 91 l->head = l->tail = new; … … 100 107 /* Create the new node */ 101 108 new = (libtrace_list_node_t *)malloc(sizeof(libtrace_list_node_t)); 102 assert(new != NULL); 109 if (!new) { 110 fprintf(stderr, "Unable to allocate memory for node in libtrace_list_push_back()\n"); 111 return; 112 } 103 113 new->data = malloc(l->element_size); 104 assert(new->data != NULL); 105 114 if (!new->data) { 115 fprintf(stderr, "Unable to allocate memory for node data in libtrace_list_push_back()\n"); 116 return; 117 } 106 118 new->next = NULL; 107 119 memcpy(new->data, item, l->element_size); 108 120 109 121 if (l->tail == NULL) { 110 assert(l->head == NULL && l->size == 0); 122 if (l->head != NULL || l->size != 0) { 123 fprintf(stderr, "Error cannot have a NULL tail with a non NULL head and a size of non 0 in libtrace_list_push_back()\n"); 124 return; 125 } 111 126 new->prev = NULL; 112 127 l->head = l->tail = new; … … 197 212 while (index--) { 198 213 ret = ret->next; 199 assert(ret != NULL); 214 if (!ret) { 215 fprintf(stderr, "Error encountered NULL index in libtrace_list_get_index()\n"); 216 return NULL; 217 } 200 218 } 201 219 -
lib/data-struct/message_queue.c
ree6e802 r2193905 43 43 void libtrace_message_queue_init(libtrace_message_queue_t *mq, size_t message_len) 44 44 { 45 assert(message_len); 45 if (!message_len) { 46 fprintf(stderr, "Message length cannot be 0 in libtrace_message_queue_init()\n"); 47 return; 48 } 46 49 ASSERT_RET(pipe(mq->pipefd), != -1); 47 50 mq->message_count = 0; … … 69 72 { 70 73 int ret; 71 assert(mq->message_len); 74 if (!mq->message_len) { 75 fprintf(stderr, "Message queue must be initialised with libtrace_message_queue_init()" 76 "before inserting messages in libtrace_message_queue_put()\n"); 77 return 0; 78 } 72 79 ASSERT_RET(write(mq->pipefd[1], message, mq->message_len), == (int) mq->message_len); 73 80 // Update after we've written -
lib/data-struct/object_cache.c
ree6e802 r2193905 143 143 */ 144 144 static void resize_memory_caches(struct local_caches *lcs) { 145 assert (lcs->t_mem_caches_total > 0); 145 if (lcs->t_mem_caches_total <= 0) { 146 fprintf(stderr, "Expected lcs->t_mem_caches_total to be greater or equal to 0 in resize_memory_caches()\n"); 147 return; 148 } 146 149 lcs->t_mem_caches += 0x10; 147 150 lcs->t_mem_caches = realloc(lcs->t_mem_caches, … … 166 169 /* This thread has not been used with a memory pool before */ 167 170 /* Allocate our TLS */ 168 assert(lcs == NULL); 171 if (lcs) { 172 fprintf(stderr, "Expected lcs to be NULL in get_local_caches()\n"); 173 return NULL; 174 } 169 175 lcs = calloc(1, sizeof (struct local_caches)); 170 assert(lcs); 176 if (!lcs) { 177 fprintf(stderr, "Unable to allocate memory for lcs in get_local_caches()\n"); 178 return NULL; 179 } 171 180 /* Hook into pthreads to destroy this when the thread ends */ 172 181 pthread_once(&memory_destructor_once, &once_memory_cache_key_init); … … 174 183 lcs->t_mem_caches_total = 0x10; 175 184 lcs->t_mem_caches = calloc(0x10, sizeof(struct local_cache)); 176 assert(lcs); 177 assert(lcs->t_mem_caches); 185 if (!lcs->t_mem_caches) { 186 fprintf(stderr, "Unable to allocate memory for lcs->t_mem_caches in get_local_caches()\n"); 187 return NULL; 188 } 178 189 return lcs; 179 190 } … … 210 221 } 211 222 212 assert(!lc->invalid); 223 if (lc->invalid) { 224 fprintf(stderr, "lc cache is invalid in find_cache()\n"); 225 return NULL; 226 } 213 227 return lc; 214 228 } … … 246 260 size_t buffer_size, bool limit_size) { 247 261 248 assert(buffer_size); 249 assert(alloc); 250 assert(free); 262 if (buffer_size <= 0) { 263 fprintf(stderr, "NULL buffer_size passed into libtrace_ocache_init()\n"); 264 return -1; 265 } 266 if (!alloc) { 267 fprintf(stderr, "NULL alloc passed into libtrace_ocache_init()\n"); 268 return -1; 269 } 270 if (!free) { 271 fprintf(stderr, "NULL free method passed into libtrace_ocache_init()\n"); 272 return -1; 273 } 251 274 if (libtrace_ringbuffer_init(&oc->rb, buffer_size, LIBTRACE_RINGBUFFER_BLOCKING) != 0) { 252 275 return -1; … … 366 389 mem_hits.read.miss += nb_buffers - i; 367 390 #endif 368 assert(i >= min_nb_buffers); 391 if (i < min_nb_buffers) { 392 fprintf(stderr, "Unable to fill remaining cache in libtrace_ocache_alloc_cache()\n"); 393 return ~0U; 394 } 369 395 return i; 370 396 } … … 376 402 bool try_alloc = !(oc->max_allocations && oc->max_allocations <= oc->current_allocations); 377 403 378 assert(oc->max_allocations ? nb_buffers < oc->max_allocations : 1); 404 if (oc->max_allocations) { 405 if(nb_buffers >= oc->max_allocations) { 406 fprintf(stderr, "Expected nb_buffers to be less than or equal to the object cache " 407 "max allocation in libtrace_ocache_alloc()\n"); 408 return ~0U; 409 } 410 } 379 411 min = try_alloc ? 0: min_nb_buffers; 380 412 if (lc) … … 399 431 for (;i < nb; ++i) { 400 432 values[i] = (*oc->alloc)(); 401 assert(values[i]); 402 } 403 assert (i == nb); 433 if (!values[i]) { 434 fprintf(stderr, "Unable to alloc memory for values[%zu] in libtrace_ocache_alloc()\n", i); 435 return ~0U; 436 } 437 } 438 439 if (i != nb) { 440 fprintf(stderr, "Expected i == nb in libtrace_ocache_alloc()\n"); 441 return ~0U; 442 } 404 443 // Still got to wait for more 405 444 if (nb < min_nb_buffers) { … … 410 449 } 411 450 } 412 assert(i >= min_nb_buffers); 451 if (i < min_nb_buffers) { 452 fprintf(stderr, "Failed to allocate minimum number of buffers for libtrace " 453 "object cache in libtrace_ocache_alloc()\n"); 454 return ~0U; 455 } 413 456 return i; 414 457 } … … 487 530 size_t min; 488 531 489 assert(oc->max_allocations ? nb_buffers < oc->max_allocations : 1); 532 if (oc->max_allocations) { 533 if(nb_buffers >= oc->max_allocations) { 534 fprintf(stderr, "Expected nb_buffers to be less than or equal to the object cache " 535 "max allocation in libtrace_ocache_alloc()\n"); 536 return ~0U; 537 } 538 } 490 539 min = oc->max_allocations ? min_nb_buffers : 0; 491 540 if (lc) -
lib/data-struct/ring_buffer.c
ree6e802 r2193905 268 268 size_t nb_ready; 269 269 size_t i = 0; 270 271 assert(min_nb_buffers <= nb_buffers); 270 271 if (min_nb_buffers > nb_buffers) { 272 fprintf(stderr, "min_nb_buffers must be greater than or equal to nb_buffers in libtrace_ringbuffer_write_bulk()\n"); 273 return ~0U; 274 } 272 275 if (!min_nb_buffers && libtrace_ringbuffer_is_full(rb)) 273 276 return 0; … … 346 349 size_t nb_ready; 347 350 size_t i = 0; 348 349 assert(min_nb_buffers <= nb_buffers); 351 352 if (min_nb_buffers > nb_buffers) { 353 fprintf(stderr, "min_nb_buffers must be greater than or equal to nb_buffers in libtrace_ringbuffer_write_bulk()\n"); 354 return ~0U; 355 } 350 356 351 357 if (!min_nb_buffers && libtrace_ringbuffer_is_empty(rb)) -
lib/data-struct/sliding_window.c
ree6e802 r2193905 27 27 28 28 #include <stdlib.h> 29 #include <assert.h>30 29 #include <string.h> 31 30 31 #include <stdio.h> 32 32 /** 33 33 * Implements a sliding window via a ring buffer, this is a fixed size. … … 43 43 sw->start = 0; 44 44 sw->elements = calloc(sw->size, sizeof(void*)); 45 assert(sw->elements); 45 if (!sw->elements) { 46 fprintf(stderr, "Unable to allocate memory for sw->elements in libtrace_slidingwindow_init()\n"); 47 return; 48 } 46 49 memset((void *) sw->elements, 0, sizeof(void*) * sw->size); 47 50 sw->start_number = start_number; -
lib/data-struct/vector.c
ree6e802 r2193905 54 54 v->max_size *= 2; 55 55 v->elements = realloc(v->elements, v->max_size * v->element_size); 56 assert(v->elements); 56 if (!v->elements) { 57 fprintf(stderr, "Unable to allocate memory for v->elements in libtrace_vector_push_back()\n"); 58 return; 59 } 57 60 } 58 61 memcpy(&v->elements[v->size*v->element_size], d, v->element_size); … … 104 107 DLLEXPORT void libtrace_vector_append(libtrace_vector_t *dest, libtrace_vector_t *src) 105 108 { 106 assert(dest->element_size == src->element_size); 109 if (dest->element_size != src->element_size) { 110 fprintf(stderr, "Elements must be the same size in libtrace_vector_append()\n"); 111 return; 112 } 107 113 if (src->size == 0) // Nothing to do if this is the case 108 114 return; -
lib/format_atmhdr.c
r32ee9b2 r2193905 34 34 35 35 #include <sys/stat.h> 36 #include <assert.h>37 36 #include <errno.h> 38 37 #include <fcntl.h> -
lib/format_bpf.c
ra0f031b r2193905 123 123 124 124 /* Initialises a BPF input trace */ 125 static int bpf_init_input(libtrace_t *libtrace) 126 { 125 static int bpf_init_input(libtrace_t *libtrace) { 127 126 libtrace->format_data = (struct libtrace_format_data_t *) 128 127 malloc(sizeof(struct libtrace_format_data_t)); 129 128 129 if (!libtrace->format_data) { 130 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory " 131 "for format data inside bpf_init_input()"); 132 return -1; 133 } 134 130 135 /* Throw some default values into the format data */ 131 136 FORMATIN(libtrace)->fd = -1; -
lib/format_dag24.c
r32ee9b2 r2193905 33 33 #include "format_erf.h" 34 34 35 #include <assert.h>36 35 #include <errno.h> 37 36 #include <fcntl.h> … … 179 178 return -1; 180 179 } 181 180 182 181 dag_init_format_data(libtrace); 183 182 if (S_ISCHR(buf.st_mode)) { … … 326 325 return NULL; 327 326 size = ntohs(erfptr->rlen); 328 assert( size >= dag_record_size ); 327 if (size < dag_record_size) { 328 fprintf(stderr, "DAG2.4 rlen is invalid (rlen = %u, must be at least %u)\n", 329 size, dag_record_size); 330 return NULL; 331 } 329 332 FORMAT_DATA->offset += size; 330 333 FORMAT_DATA->diff -= size; … … 480 483 } while (1); 481 484 482 483 /* We only want to sleep for a very short time */484 assert(data == 0);485 485 event.type = TRACE_EVENT_SLEEP; 486 486 event.seconds = 0.0001; -
lib/format_dag25.c
r32ee9b2 r2193905 33 33 #include "format_erf.h" 34 34 35 #include <assert.h>36 35 #include <errno.h> 37 36 #include <fcntl.h> … … 245 244 FORMAT_DATA->per_stream = 246 245 libtrace_list_init(sizeof(stream_data)); 247 assert(FORMAT_DATA->per_stream != NULL); 246 if (FORMAT_DATA->per_stream == NULL) { 247 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, 248 "Unable to create list for stream in dag_init_format_data()"); 249 return -1; 250 } 248 251 249 252 /* We'll start with just one instance of stream_data, and we'll … … 284 287 { 285 288 /* Need to remove from the device list */ 286 assert(dev->ref_count == 0); 289 if (dev->ref_count != 0) { 290 fprintf(stderr, "Cannot close DAG device with non zero reference in dag_close_device()\n"); 291 return; 292 } 287 293 288 294 if (dev->prev == NULL) { … … 522 528 dag_dev_name = NULL; 523 529 pthread_mutex_unlock(&open_dag_mutex); 530 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to open DAG device %s", dag_dev_name); 524 531 return -1; 525 532 } … … 995 1002 996 1003 size = ntohs(erfptr->rlen); 997 assert( size >= dag_record_size ); 1004 if (size < dag_record_size) { 1005 fprintf(stderr, "DAG2.5 rlen is invalid (rlen %u, must be at least %u\n", 1006 size, dag_record_size); 1007 return NULL; 1008 } 998 1009 999 1010 /* Make certain we have the full packet available */ … … 1225 1236 1226 1237 /* Packet length (rlen includes format overhead) */ 1227 assert(trace_get_capture_length(packet) > 0 1228 && trace_get_capture_length(packet) <= 65536); 1229 assert(erf_get_framing_length(packet) > 0 1230 && trace_get_framing_length(packet) <= 65536); 1231 assert(trace_get_capture_length(packet) + 1232 erf_get_framing_length(packet) > 0 1233 && trace_get_capture_length(packet) + 1234 erf_get_framing_length(packet) <= 65536); 1238 if (trace_get_capture_length(packet) <= 0 1239 || trace_get_capture_length(packet) > 65536) { 1240 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 1241 "Capture length is out of range in dag_write_packet()"); 1242 return -1; 1243 } 1244 if (erf_get_framing_length(packet) <= 0 1245 || trace_get_framing_length(packet) > 65536) { 1246 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 1247 "Framing length is out of range in dag_write_packet()"); 1248 return -1; 1249 } 1250 if (trace_get_capture_length(packet) + 1251 erf_get_framing_length(packet) <= 0 1252 || trace_get_capture_length(packet) + 1253 erf_get_framing_length(packet) > 65536) { 1254 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 1255 "Capture + framing length is out of range in dag_write_packet()"); 1256 return -1; 1257 } 1235 1258 1236 1259 erfhdr.rlen = htons(trace_get_capture_length(packet) … … 1482 1505 { 1483 1506 libtrace_list_node_t *tmp; 1484 assert(stat && libtrace); 1507 if (!libtrace) { 1508 fprintf(stderr, "NULL trace passed into dag_get_statistics()\n"); 1509 return; 1510 } 1511 if (!stat) { 1512 trace_set_err(libtrace, TRACE_ERR_STAT, "NULL stat passed into dag_get_statistics()"); 1513 return; 1514 } 1485 1515 tmp = FORMAT_DATA_HEAD; 1486 1516 … … 1498 1528 libtrace_stat_t *stat) { 1499 1529 struct dag_per_stream_t *stream_data = t->format_data; 1500 assert(stat && libtrace); 1501 1530 if (!libtrace) { 1531 fprintf(stderr, "NULL trace passed into dag_get_thread_statistics()\n"); 1532 return; 1533 } 1534 if (!stat) { 1535 trace_set_err(libtrace, TRACE_ERR_STAT, "NULL stat passed into dag_get_thread_statistics()"); 1536 return; 1537 } 1502 1538 stat->dropped_valid = 1; 1503 1539 stat->dropped = stream_data->drops; -
lib/format_dpdk.c
r3b94ef2 r2193905 51 51 52 52 #include <stdlib.h> 53 #include <assert.h>54 53 #include <unistd.h> 55 54 #include <endian.h> … … 213 212 static int parse_pciaddr(char * str, struct rte_pci_addr * addr, long * core) { 214 213 int matches; 215 assert(str); 214 215 if (!str) { 216 fprintf(stderr, "NULL str passed into parse_pciaddr()\n"); 217 return -1; 218 } 216 219 #if RTE_VERSION >= RTE_VERSION_NUM(17, 8, 0, 1) 217 220 matches = sscanf(str, "%8"SCNx32":%2"SCNx8":%2"SCNx8".%2"SCNx8"-%ld", … … 325 328 int i; 326 329 327 assert (core < RTE_MAX_LCORE); 328 assert (rte_get_master_lcore() == rte_lcore_id()); 330 if (core >= RTE_MAX_LCORE) { 331 fprintf(stderr, "Core must be a value less than the number of cores " 332 "in dpdk_move_master_lcore()\n"); 333 return -1; 334 } 335 if (rte_get_master_lcore() != rte_lcore_id()) { 336 fprintf(stderr, "Master core not equal to core id in dpdk_move_master_lcore()\n"); 337 return -1; 338 } 329 339 330 340 if (core == rte_lcore_id()) … … 332 342 333 343 /* Make sure we are not overwriting someone else */ 334 assert(!rte_lcore_is_enabled(core)); 344 if (rte_lcore_is_enabled(core)) { 345 fprintf(stderr, "Cannot override another core in dpdk_move_master_lcore()\n"); 346 return -1; 347 } 335 348 336 349 /* Move the core */ … … 470 483 int max_node_cpu = -1; 471 484 struct bitmask *mask = numa_allocate_cpumask(); 472 assert(mask); 485 if (!mask) { 486 fprintf(stderr, "Unable to allocate cpu mask in dpdk_init_environment()\n"); 487 return -1; 488 } 473 489 numa_node_to_cpus(format_data->nic_numa_node, mask); 474 490 for (i = 0 ; i < nb_cpu; ++i) { … … 530 546 } 531 547 // Only the master should be running 532 assert(cfg->lcore_count == 1); 548 if (cfg->lcore_count != 1) { 549 fprintf(stderr, "Expected only the master core to be running in dpdk_init_environment()\n"); 550 return -1; 551 } 533 552 534 553 // TODO XXX TODO … … 587 606 libtrace->format_data = (struct dpdk_format_data_t *) 588 607 malloc(sizeof(struct dpdk_format_data_t)); 608 609 if (!libtrace->format_data) { 610 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 611 "format data inside dpdk_init_input()"); 612 return 1; 613 } 614 589 615 FORMAT(libtrace)->port = 0; /* Always assume 1 port loaded */ 590 616 FORMAT(libtrace)->nb_ports = 0; … … 628 654 libtrace->format_data = (struct dpdk_format_data_t *) 629 655 malloc(sizeof(struct dpdk_format_data_t)); 656 657 if (!libtrace->format_data) { 658 trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 659 "format data inside dpdk_init_output()"); 660 return -1; 661 } 630 662 FORMAT(libtrace)->port = 0; /* Always assume 1 port loaded */ 631 663 FORMAT(libtrace)->nb_ports = 0; … … 832 864 struct dpdk_format_data_t * format_data = cb_arg; 833 865 struct rte_eth_link link_info; 834 assert(event == RTE_ETH_EVENT_INTR_LSC); 835 assert(port == format_data->port); 866 if (event != RTE_ETH_EVENT_INTR_LSC) { 867 fprintf(stderr, "Received unexpected event in dpdk_lsc_callback()\n"); 868 #if RTE_VERSION >= RTE_VERSION_NUM(17, 8, 0, 1) 869 return -1; 870 #else 871 return; 872 #endif 873 } 874 if (port != format_data->port) { 875 fprintf(stderr, "Port does not match port in format data in dpdk_lsc_callback()\n"); 876 return -1; 877 } 836 878 837 879 rte_eth_link_get_nowait(port, &link_info); … … 1445 1487 struct rte_config *cfg = rte_eal_get_configuration(); 1446 1488 1447 assert(rte_lcore_id() < RTE_MAX_LCORE); 1489 if (rte_lcore_id() >= RTE_MAX_LCORE) { 1490 fprintf(stderr, "Expected core id less than or equal to RTE_MAX_LCORE in " 1491 "dpdk_punregister_thread()\n"); 1492 return; 1493 } 1448 1494 pthread_mutex_lock(&dpdk_lock); 1449 1495 /* Skip if master */ … … 1458 1504 cfg->lcore_count--; 1459 1505 RTE_PER_LCORE(_lcore_id) = -1; // Might make the world burn if used again 1460 assert(cfg->lcore_count >= 1); // We cannot unregister the master LCORE!! 1506 if (cfg->lcore_count < 1) { 1507 fprintf(stderr, "You cannot unregister the master lcore in dpdk_punregister_thread()\n"); 1508 return; 1509 } 1461 1510 pthread_mutex_unlock(&dpdk_lock); 1462 1511 return; … … 1584 1633 */ 1585 1634 static inline struct dpdk_addt_hdr * get_addt_hdr (const libtrace_packet_t *packet) { 1586 assert(packet); 1587 assert(packet->buffer); 1635 if (!packet) { 1636 fprintf(stderr, "NULL packet passed into dpdk_addt_hdr()\n"); 1637 return NULL; 1638 } 1639 if (!packet->buffer) { 1640 fprintf(stderr, "NULL packet buffer passed into dpdk_addt_hdr()\n"); 1641 return NULL; 1642 } 1588 1643 /* Our header sits straight after the mbuf header */ 1589 1644 return (struct dpdk_addt_hdr *) ((struct rte_mbuf*) packet->buffer + 1); … … 1637 1692 libtrace_packet_t *packet, void *buffer, 1638 1693 libtrace_rt_types_t rt_type, uint32_t flags) { 1639 assert(packet); 1694 if (!packet) { 1695 fprintf(stderr, "NULL packet passed into dpdk_prepare_packet()\n"); 1696 return TRACE_ERR_NULL_PACKET; 1697 } 1640 1698 if (packet->buffer != buffer && 1641 1699 packet->buf_control == TRACE_CTRL_PACKET) { … … 1939 1997 if (packets[i]->buffer != NULL) { 1940 1998 /* The packet should always be finished */ 1941 assert(packets[i]->buf_control == TRACE_CTRL_PACKET); 1999 if (packets[i]->buf_control != TRACE_CTRL_PACKET) { 2000 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Expected packet buffer " 2001 "to be empty in dpdk_pread_packets()\n"); 2002 return -1; 2003 } 1942 2004 free(packets[i]->buffer); 1943 2005 } … … 1964 2026 if (packet->buffer != NULL) { 1965 2027 /* The packet should always be finished */ 1966 assert(packet->buf_control == TRACE_CTRL_PACKET); 2028 if (packet->buf_control != TRACE_CTRL_PACKET) { 2029 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Expected packet buffer to be " 2030 "empty in dpdk_read_packet()\n"); 2031 return -1; 2032 } 1967 2033 free(packet->buffer); 1968 2034 packet->buffer = NULL; … … 2086 2152 if (packet->buffer != NULL) { 2087 2153 /* The packet should always be finished */ 2088 assert(packet->buf_control == TRACE_CTRL_PACKET); 2154 if (packet->buf_control != TRACE_CTRL_PACKET) { 2155 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Expected packet " 2156 "buffer to be empty in dpdk_trace_event()\n"); 2157 return -1; 2158 } 2089 2159 free(packet->buffer); 2090 2160 packet->buffer = NULL; -
lib/format_dpdkndag.c
r32ee9b2 rfdf23b8 7 7 #include "format_erf.h" 8 8 9 #include <assert.h>10 9 #include <errno.h> 11 10 #include <fcntl.h> … … 86 85 libtrace->format_data = (dpdkndag_format_data_t *)malloc( 87 86 sizeof(dpdkndag_format_data_t)); 87 88 if (!libtrace->format_data) { 89 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 90 "format data inside dpdkndag_init_input()"); 91 return -1; 92 } 88 93 89 94 FORMAT_DATA->localiface = NULL; -
lib/format_duck.c
r32ee9b2 r2193905 33 33 34 34 #include <errno.h> 35 #include <assert.h>36 35 #include <stdio.h> 37 36 #include <fcntl.h> … … 63 62 int fileflag; 64 63 iow_t *file; 65 int dag_version; 64 int dag_version; 66 65 }; 67 66 … … 69 68 libtrace->format_data = malloc(sizeof(struct duck_format_data_t)); 70 69 70 if (!libtrace->format_data) { 71 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 72 "format data inside duck_init_input()"); 73 return 1; 74 } 75 71 76 DATA(libtrace)->dag_version = 0; 72 77 return 0; … … 75 80 static int duck_init_output(libtrace_out_t *libtrace) { 76 81 libtrace->format_data = malloc(sizeof(struct duck_format_data_out_t)); 77 82 83 if (!libtrace->format_data) { 84 trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 85 "format data inside duck_init_output()"); 86 return -1; 87 } 88 78 89 OUTPUT->level = 0; 79 90 OUTPUT->compress_type = TRACE_OPTION_COMPRESSTYPE_NONE; … … 102 113 return -1; 103 114 } 104 assert(0); 115 trace_set_err_out(libtrace, TRACE_ERR_UNKNOWN_OPTION, 116 "Unknown option in duck_config_output()"); 117 return -1; 105 118 } 106 119 … … 233 246 234 247 if (duck_prepare_packet(libtrace, packet, packet->buffer, packet->type, 235 flags)) 236 return -1; 237 248 flags)) 249 return -1; 250 238 251 return numbytes; 239 252 } 240 253 241 static int duck_write_packet(libtrace_out_t *libtrace, 242 libtrace_packet_t *packet) 254 static int duck_write_packet(libtrace_out_t *libtrace, 255 libtrace_packet_t *packet) 243 256 { 244 257 … … 246 259 uint32_t duck_version; 247 260 248 if (packet->type != TRACE_RT_DUCK_2_4 261 if (packet->type != TRACE_RT_DUCK_2_4 249 262 && packet->type != TRACE_RT_DUCK_2_5 && 250 263 packet->type != TRACE_RT_DUCK_5_0) { … … 253 266 return -1; 254 267 } 255 256 assert(OUTPUT->file); 268 269 if (!OUTPUT->file) { 270 trace_set_err_out(libtrace, TRACE_ERR_BAD_IO, 271 "Attempted to write DUCK packets to a closed file, must call " 272 "trace_create_output() before calling trace_write_output()"); 273 return -1; 274 } 257 275 258 276 if (OUTPUT->dag_version == 0) { … … 261 279 if ((numbytes = wandio_wwrite(OUTPUT->file, &duck_version, 262 280 sizeof(duck_version))) != sizeof(uint32_t)){ 263 trace_set_err_out(libtrace, errno, 281 trace_set_err_out(libtrace, errno, 264 282 "Writing DUCK version failed"); 265 283 return -1; … … 267 285 OUTPUT->dag_version = packet->type; 268 286 } 269 270 if ((numbytes = wandio_wwrite(OUTPUT->file, packet->payload, 287 288 if ((numbytes = wandio_wwrite(OUTPUT->file, packet->payload, 271 289 trace_get_capture_length(packet))) != 272 290 (int)trace_get_capture_length(packet)) { -
lib/format_erf.c
rbccdffc r2193905 35 35 #include "wandio.h" 36 36 37 #include <assert.h>38 37 #include <errno.h> 39 38 #include <fcntl.h> … … 180 179 exthdr ++; 181 180 firstbyte = (uint8_t *)exthdr; 182 assert(extsize <= ntohs(erfptr->rlen)); 181 if (extsize > ntohs(erfptr->rlen)) { 182 trace_set_err(packet->trace, TRACE_ERR_BAD_PACKET, "Extension size is greater than dag record record length in erf_get_framing_length()"); 183 return -1; 184 } 183 185 } 184 186 } … … 225 227 } 226 228 227 static int erf_init_input(libtrace_t *libtrace) 228 { 229 static int erf_init_input(libtrace_t *libtrace) { 229 230 libtrace->format_data = malloc(sizeof(struct erf_format_data_t)); 230 231 232 if (!libtrace->format_data) { 233 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 234 "format data inside erf_init_input()"); 235 return -1; 236 } 237 231 238 IN_OPTIONS.real_time = 0; 232 239 DATA(libtrace)->drops = 0; 233 240 234 241 return 0; /* success */ 235 242 } … … 380 387 break; 381 388 case INDEX_UNKNOWN: 382 assert(0); 389 trace_set_err(libtrace, TRACE_ERR_SEEK_ERF, "Cannot seek to erf timestamp with unknown index in erf_seek_erf()"); 390 return -1; 383 391 break; 384 392 } … … 400 408 static int erf_init_output(libtrace_out_t *libtrace) { 401 409 libtrace->format_data = malloc(sizeof(struct erf_format_data_out_t)); 410 411 if (!libtrace->format_data) { 412 trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 413 "format data inside erf_init_output()"); 414 return -1; 415 } 402 416 403 417 OUT_OPTIONS.level = 0; … … 460 474 } else 461 475 packet->buf_control = TRACE_CTRL_EXTERNAL; 462 463 476 464 477 packet->type = rt_type; 465 478 packet->buffer = buffer; … … 472 485 } 473 486 474 assert(erfptr->rlen != 0); 475 487 if (erfptr->rlen == 0) { 488 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "ERF packet has an invalid record " 489 "length: zero, in erf_prepare_packet()\n"); 490 return -1; 491 } 492 476 493 if (libtrace->format_data == NULL) { 477 494 /* Allocates the format_data structure */ … … 649 666 void *payload = packet->payload; 650 667 651 assert(OUTPUT->file); 668 if (!OUTPUT->file) { 669 trace_set_err_out(libtrace, TRACE_ERR_BAD_IO, "Attempted to write ERF packets to a " 670 "closed file, must call trace_create_output() before calling trace_write_output()"); 671 return -1; 672 } 652 673 653 674 if (trace_get_link_type(packet) == TRACE_TYPE_NONDATA) … … 699 720 700 721 /* Packet length (rlen includes format overhead) */ 701 assert(trace_get_capture_length(packet)>0 702 && trace_get_capture_length(packet)<=65536); 703 assert(trace_get_framing_length(packet)<=65536); 704 722 if (trace_get_capture_length(packet) <= 0 723 || trace_get_capture_length(packet) > 65536) { 724 trace_set_err_out(libtrace, TRACE_ERR_BAD_PACKET, 725 "Capture length is out of range in erf_write_packet()"); 726 return -1; 727 } 728 if (trace_get_framing_length(packet) > 65536) { 729 trace_set_err_out(libtrace, TRACE_ERR_BAD_PACKET, 730 "Framing length is to large in erf_write_packet()"); 731 return -1; 732 } 733 705 734 if (erfhdr.type == TYPE_ETH) 706 735 framing = dag_record_size + 2; 707 736 else 708 737 framing = dag_record_size; 709 738 710 739 rlen = trace_get_capture_length(packet) + framing; 711 assert(rlen > 0 && rlen <= 65536); 740 if (rlen <= 0 || rlen > 65536) { 741 trace_set_err_out(libtrace, TRACE_ERR_BAD_PACKET, 742 "Capture + framing length is out of range in erf_write_packet()"); 743 return -1; 744 } 712 745 erfhdr.rlen = htons(rlen); 713 746 /* loss counter. Can't do this */ … … 797 830 uint16_t wlen; 798 831 799 assert(packet); 832 if (!packet) { 833 fprintf(stderr, "NULL packet passed to erf_set_capture_length()\n"); 834 return ~0U; 835 } 800 836 erfptr = (dag_record_t *)packet->header; 801 837 -
lib/format_etsilive.c
rd24b1df rd7d3267 37 37 #include <libwandder_etsili.h> 38 38 39 #include <assert.h>40 39 #include <errno.h> 41 40 #include <fcntl.h> … … 215 214 sizeof(etsilive_format_data_t)); 216 215 216 if (!libtrace->format) { 217 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 218 "format data inside etsilive_init_input()"); 219 return 1; 220 } 221 217 222 FORMAT_DATA->receivers = NULL; 218 223 FORMAT_DATA->nextthreadid = 0; … … 621 626 libtrace_t *libtrace = packet->trace; 622 627 623 assert(libtrace); 624 assert(FORMAT_DATA->shareddec); 628 if (!libtrace) { 629 fprintf(stderr, "Packet is not associated with a trace in etsilive_get_pdu_length()\n"); 630 return TRACE_ERR_NULL_TRACE; 631 } 632 if (!FORMAT_DATA->shareddec) { 633 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, "Etsilive format data shareddec is NULL in etsilive_get_pdu_length()\n"); 634 return -1; 635 } 625 636 626 637 /* 0 should be ok here for quickly evaluating the first length -
lib/format_helper.c
r412550d rd7d3267 39 39 #include "format_helper.h" 40 40 41 #include <assert.h>42 41 #include <stdarg.h> 43 42 … … 69 68 struct timeval tv; 70 69 71 assert(trace != NULL); 72 assert(packet != NULL); 73 70 if (!trace) { 71 fprintf(stderr, "NULL trace passed into trace_event_device()\n"); 72 event.type = TRACE_EVENT_TERMINATE; 73 return event; 74 } 75 if (!packet) { 76 trace_set_err(trace, TRACE_ERR_NULL_PACKET, "NULL packet passed into trace_event_device()"); 77 event.type = TRACE_EVENT_TERMINATE; 78 return event; 79 } 80 74 81 FD_ZERO(&rfds); 75 82 FD_ZERO(&rfds_param); … … 292 299 va_list va; 293 300 va_start(va,msg); 294 assert(errcode != 0 && "An error occurred, but it is unknown what it is"); 301 302 if (errcode == 0) { 303 fprintf(stderr, "An error occurred, but it is unknown what it is"); 304 return; 305 } 306 295 307 trace->err.err_num=errcode; 296 308 if (errcode>0) { … … 315 327 va_list va; 316 328 va_start(va,msg); 317 assert(errcode != 0 && "An error occurred, but it is unknown what it is"); 329 if (errcode == 0) { 330 fprintf(stderr, "An error occurred, but is is unknown what is is"); 331 return; 332 } 318 333 trace->err.err_num=errcode; 319 334 if (errcode>0) { -
lib/format_legacy.c
r32ee9b2 r2193905 34 34 35 35 #include <sys/stat.h> 36 #include <assert.h>37 36 #include <errno.h> 38 37 #include <fcntl.h> … … 258 257 break; 259 258 default: 260 assert(0); 259 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, "Invalid trace format type in legacy_read_packet()"); 260 return -1; 261 261 } 262 262 … … 392 392 static int legacypos_get_wire_length(const libtrace_packet_t *packet) { 393 393 legacy_pos_t *lpos = (legacy_pos_t *)packet->header; 394 assert(ntohl(lpos->wlen)>0); 394 395 if (ntohl(lpos->wlen) <= 0) { 396 trace_set_err(packet->trace, TRACE_ERR_BAD_PACKET, "Packet wire length is invalid (%d) " 397 "in legacypos_get_wire_length()", ntohl(lpos->wlen)); 398 return -1; 399 } 395 400 return ntohl(lpos->wlen); 396 401 } -
lib/format_linux_common.c
rebed638 r2193905 40 40 #include <unistd.h> 41 41 #include <string.h> 42 #include <assert.h>43 42 44 43 #ifdef HAVE_INTTYPES_H … … 185 184 libtrace->format_data = (struct linux_format_data_t *) 186 185 malloc(sizeof(struct linux_format_data_t)); 187 assert(libtrace->format_data != NULL); 186 187 if (!libtrace->format_data) { 188 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 189 "format data inside linuxcommon_init_input()"); 190 return -1; 191 } 188 192 189 193 FORMAT_DATA->per_stream = 190 194 libtrace_list_init(sizeof(stream_data)); 191 assert(FORMAT_DATA->per_stream != NULL); 195 196 if (!FORMAT_DATA->per_stream) { 197 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to create list for stream data linuxcommon_init_input()"); 198 return -1; 199 } 192 200 193 201 libtrace_list_push_back(FORMAT_DATA->per_stream, &stream_data); … … 211 219 libtrace->format_data = (struct linux_format_data_out_t*) 212 220 malloc(sizeof(struct linux_format_data_out_t)); 213 assert(libtrace->format_data != NULL); 221 222 if (!libtrace->format_data) { 223 trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 224 "format data inside linuxcommon_init_output()"); 225 return -1; 226 } 214 227 215 228 FORMAT_DATA_OUT->fd = -1; -
lib/format_linux_int.c
r32ee9b2 r2193905 44 44 #include <unistd.h> 45 45 #include <string.h> 46 #include <assert.h>47 46 48 47 #ifdef HAVE_INTTYPES_H … … 451 450 452 451 struct libtrace_linuxnative_header *linux_hdr = NULL; 453 assert(packet); 452 if (!packet) { 453 fprintf(stderr, "NULL packet passed into linuxnative_set_capture_length()\n"); 454 /* Return -1 on error? */ 455 return ~0U; 456 } 454 457 if (size > trace_get_capture_length(packet)) { 455 458 /* We should avoid making a packet larger */ -
lib/format_linux_ring.c
rffae0a5 rd7d3267 45 45 #include <unistd.h> 46 46 #include <string.h> 47 #include <assert.h>48 47 49 48 #ifdef HAVE_INTTYPES_H … … 149 148 150 149 /* In case we have some silly values*/ 151 assert(req->tp_block_size); 152 assert(req->tp_block_nr); 153 assert(req->tp_frame_size); 154 assert(req->tp_frame_nr); 155 assert(req->tp_block_size % req->tp_frame_size == 0); 150 if (!req->tp_block_size) { 151 fprintf(stderr, "Unexpected value of zero for req->tp_block_size in calculate_buffers()\n"); 152 } 153 if (!req->tp_block_nr) { 154 fprintf(stderr, "Unexpected value of zero for req->tp_block_nr in calculate_buffers()\n"); 155 } 156 if (!req->tp_frame_size) { 157 fprintf(stderr, "Unexpected value of zero for req->tp_frame_size in calculate_buffers()\n"); 158 } 159 if (!req->tp_frame_nr) { 160 fprintf(stderr, "Unexpected value of zero for req->tp_frame_nr in calculate_buffers()\n"); 161 } 162 if (req->tp_block_size % req->tp_frame_size != 0) { 163 fprintf(stderr, "Unexpected value of zero for req->tp_block_size %% req->tp_frame_size in calculate_buffers()\n"); 164 } 156 165 } 157 166 … … 448 457 size_t size) 449 458 { 450 assert(packet); 459 if (!packet) { 460 fprintf(stderr, "NULL packet passed into linuxring_set_capture_length()\n"); 461 /* Return -1 on error? */ 462 return ~0U; 463 } 451 464 if (size > trace_get_capture_length(packet)) { 452 465 /* We should avoid making a packet larger */ … … 507 520 packet->buf_control = TRACE_CTRL_EXTERNAL; 508 521 packet->type = TRACE_RT_DATA_LINUX_RING; 509 522 510 523 /* Fetch the current frame */ 511 524 header = GET_CURRENT_BUFFER(stream); 512 525 if ((((unsigned long) header) & (pagesize - 1)) != 0) { 513 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 514 "ring frame size is not a multiple of the page size");515 516 526 trace_set_err(libtrace, TRACE_ERR_BAD_IO, "Linux ring packet is not correctly " 527 "aligned to page size in linux_read_string()"); 528 return -1; 529 } 517 530 518 531 /* TP_STATUS_USER means that we can use the frame. … … 677 690 if (packet->buffer == NULL) 678 691 return; 692 <<<<<<< HEAD 679 693 if (!libtrace) { 680 694 return; 681 695 } 696 ======= 697 if (!packet->trace) { 698 fprintf(stderr, "Linux ring packet is not attached to a valid " 699 "trace, Unable to release it, in linuxring_fin_packet()\n"); 700 return; 701 } 702 >>>>>>> fdf23b83dbe8088f53ec27af98ec6ed7b71cc34d 682 703 683 704 /* If we own the packet (i.e. it's not a copy), we need to free it */ -
lib/format_ndag.c
r857729e r2193905 35 35 #include "format_erf.h" 36 36 37 #include <assert.h>38 37 #include <errno.h> 39 38 #include <fcntl.h> … … 286 285 sizeof(ndag_format_data_t)); 287 286 287 if (!libtrace->format_data) { 288 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 289 "format data inside ndag_init_input()"); 290 return -1; 291 } 292 288 293 FORMAT_DATA->multicastgroup = NULL; 289 294 FORMAT_DATA->portstr = NULL; … … 653 658 ssock->nextts = 0; 654 659 655 assert(ssock->nextread - ssock->saved[nr] <= ssock->savedsize[nr]); 660 if (ssock->nextread - ssock->saved[nr] > ssock->savedsize[nr]) { 661 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Walked past the end of the " 662 "nDAG receive buffer, probably due to a invalid rlen, in ndag_prepare_packet_stream()"); 663 return -1; 664 } 656 665 657 666 if (ssock->nextread - ssock->saved[nr] >= ssock->savedsize[nr]) { … … 680 689 uint32_t flags UNUSED) { 681 690 682 assert(0 && "Sending nDAG records over RT doesn't make sense! Please stop.");691 fprintf(stderr, "Sending nDAG records over RT doesn't make sense! Please stop\n"); 683 692 return 0; 684 693 … … 863 872 } 864 873 #else 865 assert(required > 0); 874 if (required <= 0) { 875 fprintf(stderr, "You are required to have atleast 1 receiver in init_receivers\n"); 876 return TRACE_ERR_INIT_FAILED; 877 } 866 878 ssock->singlemsg.msg_iov->iov_base = ssock->saved[wind]; 867 879 ssock->singlemsg.msg_iov->iov_len = ENCAP_BUFSIZE; … … 898 910 ssock->bufavail --; 899 911 900 assert(ssock->bufavail >= 0); 912 if (ssock->bufavail < 0) { 913 fprintf(stderr, "No space in buffer in check_ndag_received()\n"); 914 return -1; 915 } 901 916 if (ssock->nextwriteind >= ENCAP_BUFFERS) { 902 917 ssock->nextwriteind = 0; … … 1281 1296 src->bufavail += src->bufwaiting; 1282 1297 src->bufwaiting = 0; 1283 assert(src->bufavail >= 0 && src->bufavail <= ENCAP_BUFFERS); 1298 if (src->bufavail < 0 || src->bufavail > ENCAP_BUFFERS) { 1299 trace_set_err(libtrace, TRACE_ERR_BAD_IO, "Not enough buffer space in ndag_pread_packets()"); 1300 return -1; 1301 } 1284 1302 } 1285 1303 … … 1370 1388 src->bufavail += src->bufwaiting; 1371 1389 src->bufwaiting = 0; 1372 assert(src->bufavail >= 0 && src->bufavail <= ENCAP_BUFFERS); 1390 if (src->bufavail < 0 || src->bufavail > ENCAP_BUFFERS) { 1391 trace_set_err(libtrace, TRACE_ERR_BAD_IO, "Not enough buffer space in trace_event_ndag()"); 1392 break; 1393 } 1373 1394 } 1374 1395 -
lib/format_pcap.c
r37ee856 r2193905 31 31 32 32 #include <sys/stat.h> 33 #include <assert.h>34 33 #include <stdio.h> 35 34 #include <stdlib.h> … … 102 101 libtrace->format_data = malloc(sizeof(struct pcap_format_data_t)); 103 102 103 if (!libtrace->format_data) { 104 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 105 "format data inside pcap_init_input()"); 106 return -1; 107 } 108 104 109 INPUT.pcap = NULL; 105 110 DATA(libtrace)->filter = NULL; … … 173 178 return -1; 174 179 } 175 assert(0);180 return -1; 176 181 } 177 182 178 183 static int pcap_init_output(libtrace_out_t *libtrace) { 179 184 libtrace->format_data = malloc(sizeof(struct pcap_format_data_out_t)); 185 if (!libtrace->format_data) { 186 trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 187 "format data inside pcap_init_output()"); 188 return -1; 189 } 190 180 191 OUTPUT.trace.pcap = NULL; 181 192 OUTPUT.trace.dump = NULL; … … 186 197 #ifdef HAVE_PCAP_INJECT 187 198 libtrace->format_data = malloc(sizeof(struct pcap_format_data_out_t)); 199 if (!libtrace->format_data) { 200 trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 201 "format data inside pcapint_init_output()"); 202 return -1; 203 } 204 188 205 OUTPUT.trace.pcap = NULL; 189 206 OUTPUT.trace.dump = NULL; … … 205 222 static int pcapint_init_input(libtrace_t *libtrace) { 206 223 libtrace->format_data = malloc(sizeof(struct pcap_format_data_t)); 224 if (!libtrace->format_data) { 225 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 226 "format data inside pcapint_init_input()"); 227 return -1; 228 } 229 207 230 DATA(libtrace)->filter = NULL; 208 231 DATA(libtrace)->snaplen = LIBTRACE_PACKET_BUFSIZE; … … 240 263 return -1; 241 264 } 242 assert(0);265 return -1; 243 266 } 244 267 … … 423 446 int linktype; 424 447 uint32_t flags = 0; 425 426 assert(libtrace->format_data); 448 449 if (!libtrace->format_data) { 450 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, "Trace format data missing, " 451 "call trace_create() before calling pcap_read_packet()"); 452 return -1; 453 } 427 454 linktype = pcap_datalink(DATA(libtrace)->input.pcap); 428 455 packet->type = pcap_linktype_to_rt(linktype); … … 491 518 libtrace_packet_t *packet) 492 519 { 520 521 if (!libtrace) { 522 fprintf(stderr, "NULL trace passed into pcap_write_packet()\n"); 523 return TRACE_ERR_NULL_TRACE; 524 } 525 if (!packet) { 526 trace_set_err_out(libtrace, TRACE_ERR_NULL_PACKET, "NULL packet passed into pcap_write_packet()\n"); 527 return -1; 528 } 529 493 530 struct pcap_pkthdr pcap_pkt_hdr; 494 531 void *link; … … 575 612 pcap_pkt_hdr.len = trace_get_wire_length(packet); 576 613 577 assert(pcap_pkt_hdr.caplen<65536); 578 assert(pcap_pkt_hdr.len<65536); 614 if (pcap_pkt_hdr.caplen >= 65536) { 615 trace_set_err_out(libtrace, TRACE_ERR_BAD_HEADER, "Header capture length is larger than it should be in pcap_write_packet()"); 616 return -1; 617 } 618 if (pcap_pkt_hdr.len >= 65536) { 619 trace_set_err_out(libtrace, TRACE_ERR_BAD_HEADER, "Header wire length is larger than it should be pcap_write_packet()"); 620 return -1; 621 } 579 622 580 623 pcap_dump((u_char*)OUTPUT.trace.dump, &pcap_pkt_hdr, packet->payload); … … 670 713 671 714 static int pcap_get_capture_length(const libtrace_packet_t *packet) { 715 if (!packet) { 716 fprintf(stderr, "NULL packet passed into pcapng_get_capture_length()\n"); 717 return TRACE_ERR_NULL_PACKET; 718 } 672 719 struct pcap_pkthdr *pcapptr = 0; 673 720 pcapptr = (struct pcap_pkthdr *)packet->header; 674 assert(pcapptr->caplen<=65536); 721 if (pcapptr->caplen > 65536) { 722 trace_set_err(packet->trace, TRACE_ERR_BAD_PACKET, "Capture length is to large, Packet may be corrupt in pcap_get_capture_length()"); 723 return -1; 724 } 675 725 676 726 return pcapptr->caplen; … … 704 754 static size_t pcap_set_capture_length(libtrace_packet_t *packet,size_t size) { 705 755 struct pcap_pkthdr *pcapptr = 0; 706 assert(packet); 756 if (!packet) { 757 fprintf(stderr, "NULL packet passed to pcap_set_capture_length()\n"); 758 return TRACE_ERR_NULL_PACKET; 759 } 707 760 if (size > trace_get_capture_length(packet)) { 708 761 /* Can't make a packet larger */ … … 717 770 718 771 static int pcap_get_fd(const libtrace_t *trace) { 719 720 assert(trace->format_data); 772 if (!trace) { 773 fprintf(stderr, "NULL trace passed to pcap_get_fd()\n"); 774 return TRACE_ERR_NULL_TRACE; 775 } 776 if (!trace->format_data) { 777 /* cant do this because trace is a const? */ 778 /*trace_set_err(trace, TRACE_ERR_BAD_FORMAT, "Trace format data missing, call init_input() before calling pcap_get_fd()");*/ 779 fprintf(stderr, "Trace format data missing, call init_input() before calling pcap_get_fd()\n"); 780 return TRACE_ERR_BAD_FORMAT; 781 } 721 782 return pcap_fileno(DATA(trace)->input.pcap); 722 783 } -
lib/format_pcapfile.c
r37ee856 r2193905 31 31 32 32 #include <sys/stat.h> 33 #include <assert.h>34 33 #include <stdio.h> 35 34 #include <stdlib.h> … … 125 124 static int pcapfile_init_input(libtrace_t *libtrace) { 126 125 libtrace->format_data = malloc(sizeof(struct pcapfile_format_data_t)); 127 128 if (libtrace->format_data == NULL) {129 trace_set_err(libtrace,ENOMEM,"Out of memory");126 if (!libtrace->format_data) { 127 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 128 "format data inside pcapfile_init_input()"); 130 129 return -1; 131 130 } … … 139 138 libtrace->format_data = 140 139 malloc(sizeof(struct pcapfile_format_data_out_t)); 140 if (!libtrace->format_data) { 141 trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 142 "format data inside pcapfile_init_output()"); 143 return -1; 144 } 141 145 142 146 DATAOUT(libtrace)->file=NULL; … … 191 195 if (!DATA(libtrace)->started) { 192 196 193 if (!libtrace->io) 197 if (!libtrace->io) { 198 trace_set_err(libtrace, TRACE_ERR_BAD_IO, "Trace cannot start IO in pcapfile_start_input()"); 194 199 return -1; 200 } 195 201 196 202 err=wandio_read(libtrace->io, … … 199 205 200 206 DATA(libtrace)->started = true; 201 assert(sizeof(DATA(libtrace)->header) > 0); 202 207 if (!(sizeof(DATA(libtrace)->header) > 0)) { 208 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Trace is missing header in pcapfile_start_input()"); 209 return -1; 210 } 211 203 212 if (err<1) { 204 213 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, … … 206 215 return -1; 207 216 } 208 217 209 218 if (err != (int)sizeof(DATA(libtrace)->header)) { 210 219 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, … … 343 352 size_t bytes_to_read = 0; 344 353 345 assert(libtrace->format_data); 354 if (!libtrace->format_data) { 355 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, "Trace format data missing, " 356 "call trace_create() before calling trace_read_packet()"); 357 return -1; 358 } 346 359 347 360 packet->type = pcap_linktype_to_rt(swapl(libtrace, … … 353 366 354 367 flags |= TRACE_PREP_OWN_BUFFER; 355 368 356 369 err=wandio_read(libtrace->io, 357 370 packet->buffer, … … 377 390 return -1; 378 391 } 379 380 assert(bytes_to_read < LIBTRACE_PACKET_BUFSIZE);381 392 382 393 /* If there is no payload to read, do not ask wandio_read to try and … … 444 455 TRACE_ERR_NO_CONVERSION, 445 456 "pcap does not support this format"); 446 assert(0);447 457 return -1; 448 458 } … … 485 495 hdr.ts_usec = (uint32_t)tv.tv_usec; 486 496 hdr.caplen = trace_get_capture_length(packet); 487 assert(hdr.caplen < LIBTRACE_PACKET_BUFSIZE); 497 if (hdr.caplen >= LIBTRACE_PACKET_BUFSIZE) { 498 trace_set_err_out(out, TRACE_ERR_BAD_PACKET, "Capture length is greater than buffer size in pcap_write_packet()"); 499 return -1; 500 } 488 501 /* PCAP doesn't include the FCS in its wire length value, but we do */ 489 502 if (linktype==TRACE_TYPE_ETH) { … … 557 570 libtrace_pcapfile_pkt_hdr_t *hdr; 558 571 struct timeval ts; 559 560 assert(packet->header); 561 572 573 if (!packet) { 574 fprintf(stderr, "NULL packet passed to pcapfile_get_timeval()\n"); 575 /* Return default timeval on error? */ 576 return ts; 577 } 578 579 if (!packet->header) { 580 trace_set_err(packet->trace, TRACE_ERR_BAD_HEADER, "pcap packet with NULL header passed to " 581 "pcapfile_get_timeval()"); 582 /* Return default timeval on error? */ 583 return ts; 584 } 585 562 586 hdr = (libtrace_pcapfile_pkt_hdr_t*)packet->header; 563 587 ts.tv_sec = swapl(packet->trace,hdr->ts_sec); … … 575 599 libtrace_pcapfile_pkt_hdr_t *hdr; 576 600 struct timespec ts; 577 578 assert(packet->header); 579 601 602 if (!packet) { 603 fprintf(stderr, "NULL packet passed to pcapfile_get_timespec()"); 604 /* Return default timespec on error? */ 605 return ts; 606 } 607 608 if (!packet->header) { 609 trace_set_err(packet->trace, TRACE_ERR_BAD_HEADER, "pcap packet with NULL header passed to " 610 "pcapfile_get_timespec()"); 611 /* Return fefault timespec on error? */ 612 return ts; 613 } 614 580 615 hdr = (libtrace_pcapfile_pkt_hdr_t*)packet->header; 581 616 ts.tv_sec = swapl(packet->trace,hdr->ts_sec); … … 592 627 libtrace_pcapfile_pkt_hdr_t *pcapptr; 593 628 594 assert(packet->header); 629 if (!packet) { 630 fprintf(stderr, "NULL packet passed to pcapfile_get_capture_length()\n"); 631 return TRACE_ERR_NULL_PACKET; 632 } 633 634 if (!packet->header) { 635 trace_set_err(packet->trace, TRACE_ERR_BAD_HEADER, "pcap packet with NULL header passed to " 636 "pcapfile_get_capture_length()"); 637 return -1; 638 } 595 639 pcapptr = (libtrace_pcapfile_pkt_hdr_t *)packet->header; 596 640 … … 601 645 libtrace_pcapfile_pkt_hdr_t *pcapptr; 602 646 603 assert(packet->header); 647 if (!packet) { 648 fprintf(stderr, "NULL packet passed to pcapfile_get_wire_length()\n"); 649 return TRACE_ERR_NULL_PACKET; 650 } 651 652 if (!packet->header) { 653 trace_set_err(packet->trace, TRACE_ERR_BAD_HEADER, "pcap packet with NULL header passed to " 654 "pcapfile_get_wire_length()"); 655 return -1; 656 } 604 657 605 658 pcapptr = (libtrace_pcapfile_pkt_hdr_t *)packet->header; … … 640 693 static size_t pcapfile_set_capture_length(libtrace_packet_t *packet,size_t size) { 641 694 libtrace_pcapfile_pkt_hdr_t *pcapptr = 0; 642 assert(packet); 643 assert(packet->header); 695 696 if (!packet) { 697 fprintf(stderr, "NULL packet passed into pcapfile_set_capture_length\n"); 698 /* Return -1 on error? */ 699 return ~0U; 700 } 701 702 if (!packet->header) { 703 trace_set_err(packet->trace, TRACE_ERR_BAD_HEADER, "pcap packet with NULL header passed to " 704 "pcapfile_set_capture_length()"); 705 /* Return -1 on error? */ 706 return ~0U; 707 } 644 708 if (size > trace_get_capture_length(packet)) { 645 709 /* Can't make a packet larger */ -
lib/format_pcapng.c
re9da777 r2193905 31 31 32 32 #include <sys/stat.h> 33 #include <assert.h>34 33 #include <stdio.h> 35 34 #include <stdlib.h> … … 218 217 static int pcapng_init_input(libtrace_t *libtrace) { 219 218 libtrace->format_data = malloc(sizeof(struct pcapng_format_data_t)); 220 if (libtrace->format_data == NULL) { 221 trace_set_err(libtrace, ENOMEM, "Out of memory!"); 219 if (!libtrace->format_data) { 220 trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " 221 "format data inside pcapng_init_input()"); 222 222 return -1; 223 223 } … … 302 302 } 303 303 304 assert((char *)blockhdr < *pktbuf); 304 if ((char *)blockhdr >= *pktbuf) { 305 return NULL; 306 } 305 307 // Check if we have reached the end of the block, +4 for trailing block-size 306 308 // We cannot assume a endofopt, so we add one … … 456 458 } 457 459 458 assert(sechdr->blocktype == PCAPNG_SECTION_TYPE); 460 if (sechdr->blocktype != PCAPNG_SECTION_TYPE) { 461 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid block type in pcapng section block"); 462 return -1; 463 } 459 464 460 465 if (sechdr->ordering == 0x1A2B3C4D) { … … 531 536 532 537 if (DATA(libtrace)->byteswapped) { 533 assert(byteswap32(inthdr->blocktype) == PCAPNG_INTERFACE_TYPE); 538 if (byteswap32(inthdr->blocktype) != PCAPNG_INTERFACE_TYPE) { 539 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid block type in pcapng interface"); 540 return -1; 541 } 534 542 newint->snaplen = byteswap32(inthdr->snaplen); 535 543 newint->linktype = byteswap16(inthdr->linktype); 536 544 } else { 537 assert(inthdr->blocktype == PCAPNG_INTERFACE_TYPE); 545 if (inthdr->blocktype != PCAPNG_INTERFACE_TYPE) { 546 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid block type in pcapng interface"); 547 return -1; 548 } 538 549 newint->snaplen = inthdr->snaplen; 539 550 newint->linktype = inthdr->linktype; … … 606 617 /* Read the rest of the packet into the buffer */ 607 618 if (DATA(libtrace)->byteswapped) { 608 assert(byteswap32(hdr->blocktype) == PCAPNG_NAME_RESOLUTION_TYPE); 619 if (byteswap32(hdr->blocktype) != PCAPNG_NAME_RESOLUTION_TYPE) { 620 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid block type in pcapng name " 621 "resolution block"); 622 return -1; 623 } 609 624 } else { 610 assert(hdr->blocktype == PCAPNG_NAME_RESOLUTION_TYPE); 625 if (hdr->blocktype != PCAPNG_NAME_RESOLUTION_TYPE) { 626 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid block type in pcapng name " 627 "resolution block"); 628 return -1; 629 } 611 630 } 612 631 … … 640 659 /* Read the rest of the packet into the buffer */ 641 660 if (DATA(libtrace)->byteswapped) { 642 assert(byteswap32(hdr->blocktype) == PCAPNG_CUSTOM_TYPE || 643 byteswap32(hdr->blocktype) == PCAPNG_CUSTOM_NONCOPY_TYPE); 661 if (byteswap32(hdr->blocktype) != PCAPNG_CUSTOM_TYPE || 662 byteswap32(hdr->blocktype) != PCAPNG_CUSTOM_NONCOPY_TYPE) { 663 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid blocktype " 664 "in pcapng custom block"); 665 return -1; 666 } 644 667 } else { 645 assert(hdr->blocktype == PCAPNG_CUSTOM_TYPE || 646 hdr->blocktype == PCAPNG_CUSTOM_NONCOPY_TYPE); 668 if (hdr->blocktype != PCAPNG_CUSTOM_TYPE || 669 hdr->blocktype != PCAPNG_CUSTOM_NONCOPY_TYPE) { 670 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid blocktype " 671 "in pcapng custom block"); 672 return -1; 673 } 647 674 } 648 675 … … 677 704 /* Read the rest of the packet into the buffer */ 678 705 if (DATA(libtrace)->byteswapped) { 679 assert(byteswap32(hdr->blocktype) == PCAPNG_INTERFACE_STATS_TYPE); 706 if (byteswap32(hdr->blocktype) != PCAPNG_INTERFACE_STATS_TYPE) { 707 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid block type " 708 "in pcapng statistics block"); 709 return -1; 710 } 680 711 ifaceid = byteswap32(hdr->interfaceid); 681 712 timestamp = ((uint64_t)(byteswap32(hdr->timestamp_high)) << 32) + byteswap32(hdr->timestamp_low); 682 713 } else { 683 assert(hdr->blocktype == PCAPNG_INTERFACE_STATS_TYPE); 714 if (hdr->blocktype != PCAPNG_INTERFACE_STATS_TYPE) { 715 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid block type " 716 "in pcapng statistics block"); 717 return -1; 718 } 684 719 ifaceid = hdr->interfaceid; 685 720 timestamp = ((uint64_t)(hdr->timestamp_high) << 32) + … … 776 811 /* Read the rest of the packet into the buffer */ 777 812 if (DATA(libtrace)->byteswapped) { 778 assert(byteswap32(hdr->blocktype) == PCAPNG_SIMPLE_PACKET_TYPE); 813 if (byteswap32(hdr->blocktype) != PCAPNG_SIMPLE_PACKET_TYPE) { 814 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid block type in " 815 "pcapng simple packet block"); 816 return -1; 817 } 779 818 caplen = byteswap32(hdr->blocklen) - sizeof(pcapng_spkt_t) - 4; 780 819 /* account for trailing length field */ 781 820 } else { 782 assert(hdr->blocktype == PCAPNG_SIMPLE_PACKET_TYPE); 821 if (hdr->blocktype != PCAPNG_SIMPLE_PACKET_TYPE) { 822 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid block type in " 823 "pcapng simple packet block"); 824 return -1; 825 } 783 826 caplen = hdr->blocklen - sizeof(pcapng_spkt_t) - 4; 784 827 /* account for trailing length field */ … … 826 869 /* Read the rest of the packet into the buffer */ 827 870 if (DATA(libtrace)->byteswapped) { 828 assert(byteswap32(hdr->blocktype) == PCAPNG_ENHANCED_PACKET_TYPE); 871 if (byteswap32(hdr->blocktype) != PCAPNG_ENHANCED_PACKET_TYPE) { 872 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid block type in " 873 "pcapng enhanced packet block"); 874 return -1; 875 } 829 876 caplen = byteswap32(hdr->caplen); 830 877 ifaceid = byteswap32(hdr->interfaceid); 831 878 } else { 832 assert(hdr->blocktype == PCAPNG_ENHANCED_PACKET_TYPE); 879 if (hdr->blocktype != PCAPNG_ENHANCED_PACKET_TYPE) { 880 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Invalid block type in " 881 "pcapng enhanced packet block"); 882 return -1; 883 } 833 884 caplen = hdr->caplen; 834 885 ifaceid = hdr->interfaceid; … … 899 950 int gotpacket = 0; 900 951 952 /* Ensure trace and packet are not NULL */ 953 if (!libtrace) { 954 fprintf(stderr, "NULL trace passed into pcapng_read_packet()\n"); 955 return TRACE_ERR_NULL_TRACE; 956 } 957 if (!packet) { 958 trace_set_err(libtrace, TRACE_ERR_NULL_PACKET, "NULL packet passed into " 959 "pcapng_read_packet()\n"); 960 return -1; 961 } 962 901 963 /* Peek to get next block type */ 902 assert(libtrace->format_data); 903 assert(libtrace->io); 964 if (!libtrace->format_data) { 965 trace_set_err(libtrace, TRACE_ERR_BAD_FORMAT, "Trace has no format data in " 966 "pcapng_read_packet()"); 967 return -1; 968 } 969 if (!libtrace->io) { 970 trace_set_err(libtrace, TRACE_ERR_BAD_IO, "Trace has no valid file handle " 971 "attached to it in pcapng_read_packet()"); 972 return -1; 973 } 904 974 905 975 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { … … 1042 1112 pcapng_interface_t *interface; 1043 1113 1044 assert(packet->header); 1114 if (!packet) { 1115 fprintf(stderr, "NULL packet passed into pcapng_get_timespec()"); 1116 /* Return default timespec on error? */ 1117 return ts; 1118 } 1119 if (!packet->header) { 1120 trace_set_err(packet->trace, TRACE_ERR_BAD_PACKET, "NULL header in packet in pcapng_get_timespec()"); 1121 /* Return default timespec on error? */ 1122 return ts; 1123 } 1045 1124 1046 1125 ts.tv_sec = 0; -
lib/format_rt.c
r32ee9b2 r2193905 37 37 38 38 #include <sys/stat.h> 39 #include <assert.h>40 39 #include <errno.h> 41 40 #include <fcntl.h> … … 233 232 234 233 /* If the user specifies "rt:" then assume localhost and the default 235 * port */ 234 * port */ 236 235 if (strlen(uridata) == 0) { 237 236 RT_INFO->hostname = … … 611 610 packet->payload = RT_INFO->buf_read + sizeof(rt_header_t); 612 611 packet->internalid = libtrace_push_into_bucket(RT_INFO->bucket); 613 assert(packet->internalid != 0); 612 if (!packet->internalid) { 613 trace_set_err(libtrace, TRACE_ERR_RT_FAILURE, "packet->internalid is 0 in rt_get_next_packet()"); 614 return -1; 615 } 614 616 packet->srcbucket = RT_INFO->bucket; 615 617 packet->buf_control = TRACE_CTRL_EXTERNAL; … … 756 758 libtrace_err_t read_err; 757 759 758 assert(trace); 759 assert(packet); 760 760 if (!trace) { 761 fprintf(stderr, "NULL trace passed into trace_event_rt()\n"); 762 /* Return empty event on error? */ 763 return event; 764 } 765 if (!packet) { 766 trace_set_err(trace, TRACE_ERR_NULL_PACKET, "NULL packet passed into trace_event_rt()"); 767 /* Return empty event on error? */ 768 return event; 769 } 770 761 771 if (trace->format->get_fd) { 762 772 event.fd = trace->format->get_fd(trace); -
lib/format_tsh.c
r32ee9b2 r2193905 31 31 #include "format_helper.h" 32 32 33 #include <assert.h>34 33 #include <errno.h> 35 34 #include <fcntl.h> -
lib/libtrace.h.in
rfe4940e rf6f3ae5 307 307 TRACE_ERR_UNSUPPORTED_COMPRESS = -11, 308 308 /** Wandio has returned an error */ 309 TRACE_ERR_WANDIO_FAILED = -12 309 TRACE_ERR_WANDIO_FAILED = -12, 310 /** Input URI (file) not found */ 311 TRACE_ERR_URI_NOT_FOUND = -13, 312 /** NULL passed to create trace **/ 313 TRACE_ERR_URI_NULL = -14, 314 /** NULL trace passed to trace_start **/ 315 TRACE_ERR_NULL_TRACE = -15, 316 /** Unable to finish last packet in trace_pause **/ 317 TRACE_ERR_PAUSE_FIN = -16, 318 /** Packet is NULL **/ 319 TRACE_ERR_NULL_PACKET = -17, 320 /** Filter is NULL **/ 321 TRACE_ERR_NULL_FILTER = -18, 322 /** Buffer is NULL **/ 323 TRACE_ERR_NULL_BUFFER = -19, 324 /** Trace stats err **/ 325 TRACE_ERR_STAT = -20, 326 /** Unable to create deadtrace **/ 327 TRACE_ERR_CREATE_DEADTRACE = -21, 328 /** Bad linktype **/ 329 TRACE_ERR_BAD_LINKTYPE = -22, 330 /** Bad IO for the trace **/ 331 TRACE_ERR_BAD_IO = -23, 332 /** Trace has bad header **/ 333 TRACE_ERR_BAD_HEADER = -24, 334 /** Trace err seeking by erf **/ 335 TRACE_ERR_SEEK_ERF = -25, 336 /** Trace err combiner **/ 337 TRACE_ERR_COMBINER = -26, 338 /** Error pausing processing thread **/ 339 TRACE_ERR_PAUSE_PTHREAD = -27, 340 /** Error with trace thread **/ 341 TRACE_ERR_THREAD = -28, 342 /** Thread in unexpecting state **/ 343 TRACE_ERR_THREAD_STATE = -29, 344 /** Trace configuration error **/ 345 TRACE_ERR_CONFIG = -30, 346 /** NULL passed misc **/ 347 TRACE_ERR_NULL = -31, 310 348 }; 311 349 … … 401 439 TRACE_FORMAT_DPDK_NDAG =20, /**< DAG multicast over a network, received via DPDK */ 402 440 TRACE_FORMAT_ETSILIVE =21, /**< ETSI LI over a network */ 441 TRACE_FORMAT_UNKNOWN =22, /** Unknown format */ 403 442 }; 404 443 -
lib/linktypes.c
r91bd90e r2193905 28 28 29 29 #include "rt_protocol.h" 30 #include <assert.h>31 30 #include "libtrace_int.h" 32 31 #include <stdlib.h> … … 162 161 163 162 fprintf(stderr, "Error: RT type %u cannot be converted to a pcap DLT\n", rt_type); 164 assert(false);165 163 return 0; /* satisfy warnings */ 166 164 } -
lib/protocols_l2.c
rfe4940e r2193905 27 27 #include "libtrace.h" 28 28 #include "protocols.h" 29 #include <assert.h>30 29 #include <stdlib.h> 31 30 #include <string.h> … … 194 193 */ 195 194 void *trace_get_payload_from_mpls(void *ethernet, uint16_t *type, 196 uint32_t *remaining) 197 { 198 199 assert(type); 195 uint32_t *remaining) { 196 /* Ensure supplied type is not NULL */ 197 if (!type) { 198 fprintf(stderr, "NULL type passed into trace_get_payload_from_mpls()\n"); 199 return NULL; 200 } 201 200 202 if ((((char*)ethernet)[2]&0x01)==0) { 201 203 /* The MPLS Stack bit is set */ … … 327 329 void *trace_get_payload_from_pppoe(void *link, uint16_t *type, 328 330 uint32_t *remaining) { 329 assert(type); 330 331 /* Ensure type supplied is not NULL */ 332 if (!type) { 333 fprintf(stderr, "NULL type passed into trace_get_payload_from_pppoe()\n"); 334 return NULL; 335 } 336 331 337 if (remaining) { 332 338 if (*remaining < sizeof(libtrace_pppoe_t)) { … … 437 443 uint32_t dummyrem; 438 444 void *meta = NULL; 439 440 assert(packet != NULL); 441 assert(linktype != NULL); 445 446 if (!packet) { 447 fprintf(stderr, "NULL packet passed into trace_get_layer2()\n"); 448 return NULL; 449 } 450 if (!linktype) { 451 fprintf(stderr, "NULL linktype passed into trace_get_layer2()\n"); 452 return NULL; 453 } 442 454 443 455 if (remaining == NULL) … … 668 680 669 681 DLLEXPORT uint8_t *trace_get_source_mac(libtrace_packet_t *packet) { 682 /* Ensure the supplied packet is not NULL */ 683 if (!packet) { 684 fprintf(stderr, "NULL packet passed into trace_get_source_mac()\n"); 685 return NULL; 686 } 687 670 688 void *link; 671 689 uint32_t remaining; 672 690 libtrace_linktype_t linktype; 673 assert(packet);674 691 link = trace_get_layer2(packet,&linktype,&remaining); 675 692 … … 705 722 case TRACE_TYPE_80211_RADIO: 706 723 case TRACE_TYPE_ETSILI: 707 assert(!"Metadata headers should already be skipped");708 break;724 fprintf(stderr, "Metadata headers should already be skipped in trace_get_source_mac()\n"); 725 return NULL; 709 726 } 710 727 fprintf(stderr,"%s not implemented for linktype %i\n", __func__, linktype); 711 assert(0);712 728 return NULL; 713 729 } 714 730 715 DLLEXPORT uint8_t *trace_get_destination_mac(libtrace_packet_t *packet) 716 { 731 DLLEXPORT uint8_t *trace_get_destination_mac(libtrace_packet_t *packet) { 732 /* Ensure the supplied packet is not NULL */ 733 if (!packet) { 734 fprintf(stderr, "NULL packet passed into trace_get_destination_mac()\n"); 735 return NULL; 736 } 737 717 738 void *link; 718 739 libtrace_linktype_t linktype; … … 757 778 case TRACE_TYPE_80211_RADIO: 758 779 case TRACE_TYPE_ETSILI: 759 assert(!"Metadata headers should already be skipped");760 break;780 fprintf(stderr, "Metadata headers should already be skipped in trace_get_destination_mac()\n"); 781 return NULL; 761 782 } 762 783 fprintf(stderr,"Not implemented\n"); 763 assert(0);764 784 return NULL; 765 785 } -
lib/protocols_l3.c
r6654714 r2193905 29 29 #include "protocols.h" 30 30 #include "checksum.h" 31 #include <assert.h>32 31 #include <stdlib.h> 33 32 #include <arpa/inet.h> … … 103 102 void *trans_ptr = 0; 104 103 105 assert(ipptr != NULL); 106 104 if (!ipptr) { 105 fprintf(stderr, "NULL libtrace_ip_t pointer passed into trace_get_payload_from_ip()\n"); 106 return NULL; 107 } 108 107 109 /* Er? IPv5? */ 108 110 if (ipptr->ip_v != 4) … … 137 139 138 140 void *trace_get_payload_from_ip6(libtrace_ip6_t *ipptr, uint8_t *prot, 139 uint32_t *remaining) 140 { 141 uint32_t *remaining) { 141 142 void *payload = (char*)ipptr+sizeof(libtrace_ip6_t); 142 143 uint8_t nxt; 143 144 uint16_t len; 144 145 145 assert (ipptr != NULL); 146 nxt = ipptr->nxt; 146 if (!ipptr) { 147 fprintf(stderr, "NULL libtrace_ip6_t passed into trace_get_payload_from_ip6()\n"); 148 return NULL; 149 } 150 151 nxt = ipptr->nxt; 147 152 if (remaining) { 148 153 if (*remaining<sizeof(libtrace_ip6_t)) { … … 342 347 return 1; 343 348 } 344 assert(0);345 349 } 346 350 … … 348 352 int spacelen) { 349 353 350 assert(addrptr && space); 351 assert(spacelen > 0); 352 354 if (!addrptr) { 355 fprintf(stderr, "NULL sockaddr passed into sockaddr_to_string()\n"); 356 return NULL; 357 } 358 if (!space) { 359 fprintf(stderr, "NULL buffer space passed into sockaddr_to_string()\n"); 360 return NULL; 361 } 362 if (spacelen <= 0) { 363 fprintf(stderr, "Buffer size must be greater than 0 when passed into sockaddr_to_string()\n"); 364 return NULL; 365 } 366 353 367 if (addrptr->sa_family == AF_INET) { 354 368 struct sockaddr_in *v4 = (struct sockaddr_in *)addrptr; -
lib/protocols_ospf.c
ree6e802 r2193905 27 27 #include "libtrace.h" 28 28 #include "protocols.h" 29 #include <assert.h>30 29 #include <stdlib.h> 31 30 #include <stdio.h> // fprintf … … 41 40 remaining = &dummy_rem; 42 41 43 assert(version != NULL && "version may not be NULL when calling trace_get_ospf_header!"); 42 if (!packet) { 43 fprintf(stderr, "NULL packet passed into trace_get_ospf_version()\n"); 44 return NULL; 45 } 46 if (!version) { 47 fprintf(stderr, "NULL version passed into trace_get_ospf_version()\n"); 48 return NULL; 49 } 44 50 45 51 ospf = trace_get_transport(packet, &proto, remaining); … … 62 68 char *ptr; 63 69 64 assert(remaining != NULL && "remaining may not be NULL when calling trace_get_ospf_contents!"); 70 if (!remaining) { 71 fprintf(stderr, "Remaining may not be NULL when calling trace_get_ospf_contents()\n"); 72 return NULL; 73 } 74 if (!header) { 75 fprintf(stderr, "Header may not be NULL when calling trace_get_ospf_contents()\n"); 76 return NULL; 77 } 65 78 66 79 if (!ospf_type) 67 80 ospf_type = &dummy_type; 68 81 69 if ( !header ||*remaining < sizeof(libtrace_ospf_v2_t)) {82 if (*remaining < sizeof(libtrace_ospf_v2_t)) { 70 83 *ospf_type = 0; 71 84 *remaining = 0; … … 87 100 88 101 unsigned char *link_ptr = NULL; 89 assert(remaining != NULL && "remaining may not be NULL when calling trace_get_first_link_from_router_lsa_v2!"); 90 91 if (!lsa || *remaining < sizeof(libtrace_ospf_router_lsa_v2_t)) { 102 if (!remaining) { 103 fprintf(stderr, "Remaining may not be NULL when calling trace_get_first_link_from_router_lsa_v2()\n"); 104 return NULL; 105 } 106 if (!lsa) { 107 fprintf(stderr, "NULL lsa passed into trace_get_first_link_from_router_lsa_v2()\n"); 108 return NULL; 109 } 110 111 if (*remaining < sizeof(libtrace_ospf_router_lsa_v2_t)) { 92 112 *remaining = 0; 93 113 return NULL; … … 106 126 unsigned char *lsa_ptr = NULL; 107 127 108 assert(remaining != NULL && "remaining may not be NULL when calling trace_get_first_ospf_v2_lsa!"); 109 110 if (!db_desc || *remaining < sizeof(libtrace_ospf_db_desc_v2_t)) { 128 if (!remaining) { 129 fprintf(stderr, "Remaining may not be NULL when calling trace_get_first_ospf_v2_lsa()\n"); 130 return NULL; 131 } 132 if (!db_desc) { 133 fprintf(stderr, "db_desc may not be NULL when calling trace_get_first_ospf_v2_lsa()\n"); 134 return NULL; 135 } 136 137 if (*remaining < sizeof(libtrace_ospf_db_desc_v2_t)) { 111 138 *remaining = 0; 112 139 return NULL; … … 125 152 unsigned char *lsa_ptr = NULL; 126 153 127 assert(remaining != NULL && "remaining may not be NULL when calling trace_get_first_ospf_v2_lsa!"); 128 129 if (!ls_update || *remaining < sizeof(libtrace_ospf_ls_update_t)) { 154 if (!remaining) { 155 fprintf(stderr, "Remaining may not be NULL when calling " 156 "trace_get_first_ospf_lsa_from_update_v2()\n"); 157 return NULL; 158 } 159 if (!ls_update) { 160 fprintf(stderr, "ls_update may not be NULL when calling " 161 "trace_get_first_ospf_lsa_from_update_v2()\n"); 162 return NULL; 163 } 164 165 if (*remaining < sizeof(libtrace_ospf_ls_update_t)) { 130 166 *remaining = 0; 131 167 return NULL; … … 143 179 uint32_t metric = 0; 144 180 145 assert(as_lsa); 181 if (!as_lsa) { 182 fprintf(stderr, "NULL as_lsa passed into trace_get_ospf_metric_from_as_external_lsa_v2()\n"); 183 /* Return metric of 0 on error? */ 184 return metric; 185 } 146 186 147 187 metric = as_lsa->metric_a << 16; … … 157 197 uint32_t metric = 0; 158 198 159 assert(sum_lsa); 199 if (!sum_lsa) { 200 fprintf(stderr, "NULL sum_lsa passed into trace_get_ospf_metric_from_summary_lsa_v2()\n"); 201 /* Return metric of 0 on error? */ 202 return metric; 203 } 160 204 161 205 metric = sum_lsa->metric_a << 16; -
lib/protocols_pktmeta.c
r37ee856 r2193905 27 27 #include "libtrace.h" 28 28 #include "protocols.h" 29 #include <assert.h>30 29 31 30 #ifdef HAVE_WANDDER … … 156 155 uint32_t dummyrem; 157 156 void *pktbuf = NULL; 158 assert(packet != NULL); 159 assert(linktype != NULL); 160 161 if (remaining == NULL) 157 if (!packet) { 158 fprintf(stderr, "NULL packet passed into trace_get_packet_meta()"); 159 return NULL; 160 } 161 if (!linktype) { 162 fprintf(stderr, "NULL linkype passed into trace_get_packet_meta()"); 163 return NULL; 164 } 165 166 if (remaining == NULL) 162 167 remaining = &dummyrem; 163 168 164 169 pktbuf = trace_get_packet_buffer(packet, linktype, remaining); 165 170 switch (*linktype) { … … 198 203 uint32_t *remaining) 199 204 { 200 void *nexthdr; 205 void *nexthdr; 201 206 uint16_t arphrd = 0; 202 207 uint16_t next = 0; 203 204 assert(meta != NULL); 205 assert(linktype != NULL); 206 assert(remaining != NULL); 207 208 209 if (!meta) { 210 fprintf(stderr, "NULL meta passed into trace_get_payload_from_meta()"); 211 return NULL; 212 } 213 if (!linktype) { 214 fprintf(stderr, "NULL linktype passed into trace_get_payload_from_meta()"); 215 return NULL; 216 } 217 if (!remaining) { 218 fprintf(stderr, "NULL remaining passed into trace_get_payload_from_meta()"); 219 return NULL; 220 } 221 208 222 switch(*linktype) { 209 223 case TRACE_TYPE_LINUX_SLL: -
lib/protocols_transport.c
r54a76f2 r2193905 29 29 #include "protocols.h" 30 30 #include "checksum.h" 31 #include <assert.h>32 31 #include <stdlib.h> 33 32 #include <stdio.h> // fprintf … … 568 567 sum += add_checksum(header, (uint16_t)plen); 569 568 *csum = ntohs(finish_checksum(sum)); 570 //assert(0); 571 569 572 570 return (uint16_t *)csum_ptr; 573 571 } -
lib/trace.c
r4161a69 rd7d3267 122 122 char *ret=(char*)malloc(n+1); 123 123 if (ret==NULL) { 124 fprintf(stderr,"Out of memory ");124 fprintf(stderr,"Out of memory\n"); 125 125 exit(EXIT_FAILURE); 126 126 } … … 201 201 202 202 libtrace->io = wandio_create(filename); 203 if (!libtrace->io) 203 if (!libtrace->io) { 204 trace_set_err(libtrace,TRACE_ERR_URI_NOT_FOUND,"Unable to find URI (%s)", filename); 204 205 return; 206 } 205 207 206 208 /* Try and guess based on file magic */ … … 216 218 * used to probe the file magic */ 217 219 wandio_destroy(libtrace->io); 220 trace_set_err(libtrace,TRACE_ERR_BAD_FORMAT,"Unable to guess format (%s)", filename); 218 221 return; 219 222 } … … 247 250 trace_init(); 248 251 249 assert(uri && "Passing NULL to trace_create makes me a very sad program");250 251 252 if (!libtrace) { 252 /* Out of memory */ 253 return NULL; 253 fprintf(stderr, "Unable to allocate memory in trace_create()\n"); 254 return NULL; 255 } 256 257 if(!uri) { 258 trace_set_err(libtrace, TRACE_ERR_URI_NULL, "NULL uri passed to trace_create()"); 259 return libtrace; 254 260 } 255 261 … … 272 278 libtrace->accepted_packets = 0; 273 279 libtrace->last_packet = NULL; 274 280 275 281 /* Parallel inits */ 276 282 ASSERT_RET(pthread_mutex_init(&libtrace->libtrace_lock, NULL), == 0); … … 306 312 /* Could not parse the URI nicely */ 307 313 guess_format(libtrace,uri); 308 if (!libtrace->format) { 309 trace_set_err(libtrace,TRACE_ERR_BAD_FORMAT,"Unable to guess format (%s)",uri); 314 if (trace_is_err(libtrace)) { 310 315 return libtrace; 311 316 } … … 339 344 if (libtrace->format->init_input) { 340 345 int err=libtrace->format->init_input(libtrace); 341 assert (err==-1 || err==0);342 346 if (err==-1) { 343 347 /* init_input should call trace_set_err to set the … … 398 402 libtrace->accepted_packets = 0; 399 403 libtrace->last_packet = NULL; 400 404 401 405 /* Parallel inits */ 402 406 ASSERT_RET(pthread_mutex_init(&libtrace->libtrace_lock, NULL), == 0); … … 498 502 499 503 if (libtrace->format->init_output) { 500 /* 0 on success, -1 on failure */ 501 switch(libtrace->format->init_output(libtrace)) { 502 case -1: /* failure */ 503 return libtrace; 504 case 0: /* success */ 505 break; 506 default: 507 assert(!"Internal error: init_output() should return -1 for failure, or 0 for success"); 504 int err = libtrace->format->init_output(libtrace); 505 if (err == -1) { 506 /* init_output should call trace_set_err to set the 507 * error message 508 */ 509 return libtrace; 508 510 } 509 511 } else { … … 527 529 DLLEXPORT int trace_start(libtrace_t *libtrace) 528 530 { 529 assert(libtrace); 531 if(!libtrace) { 532 fprintf(stderr, "NULL trace passed to trace_start()\n"); 533 return TRACE_ERR_NULL_TRACE; 534 } 535 530 536 if (trace_is_err(libtrace)) 531 537 return -1; … … 544 550 DLLEXPORT int trace_start_output(libtrace_out_t *libtrace) 545 551 { 546 assert(libtrace); 552 if(!libtrace) { 553 fprintf(stderr, "NULL trace passed to trace_start_output()\n"); 554 return TRACE_ERR_NULL_TRACE; 555 } 547 556 if (libtrace->format->start_output) { 548 557 int ret=libtrace->format->start_output(libtrace); … … 558 567 DLLEXPORT int trace_pause(libtrace_t *libtrace) 559 568 { 560 assert(libtrace); 569 if(!libtrace) { 570 fprintf(stderr, "NULL trace passed to trace_pause()\n"); 571 return TRACE_ERR_NULL_TRACE; 572 } 561 573 if (!libtrace->started) { 562 574 trace_set_err(libtrace,TRACE_ERR_BAD_STATE, "You must call trace_start() before calling trace_pause()"); … … 567 579 if (!libtrace_parallel && libtrace->last_packet) 568 580 trace_fin_packet(libtrace->last_packet); 569 assert(libtrace->last_packet == NULL); 581 if(libtrace->last_packet != NULL) { 582 trace_set_err(libtrace, TRACE_ERR_PAUSE_FIN, "Unable to remove all data stored against trace in trace_pause()"); 583 return -1; 584 } 570 585 571 586 if (libtrace->format->pause_input) … … 707 722 DLLEXPORT void trace_destroy(libtrace_t *libtrace) { 708 723 int i; 709 assert(libtrace); 724 725 if(!libtrace) { 726 fprintf(stderr, "NULL trace passed to trace_destroy()\n"); 727 return; 728 } 710 729 711 730 ASSERT_RET(pthread_mutex_destroy(&libtrace->libtrace_lock), == 0); … … 728 747 trace_fin_packet(libtrace->last_packet); 729 748 } 730 assert(libtrace->last_packet == NULL); 749 if (libtrace->last_packet != NULL) { 750 trace_set_err(libtrace, TRACE_ERR_PAUSE_FIN, "Unable to remove all data stored against trace in trace_destroy()"); 751 return; 752 } 731 753 732 754 if (libtrace->format) { … … 742 764 if (libtrace->stats) 743 765 free(libtrace->stats); 744 766 745 767 /* Empty any packet memory */ 746 768 if (libtrace->state != STATE_NEW) { … … 796 818 797 819 DLLEXPORT void trace_destroy_dead(libtrace_t *libtrace) { 798 assert(libtrace); 820 if(!libtrace) { 821 fprintf(stderr, "NULL trace passed to trace_destroy_dead()\n"); 822 return; 823 } 799 824 800 825 ASSERT_RET(pthread_mutex_destroy(&libtrace->libtrace_lock), == 0); … … 813 838 * @param libtrace the output trace file to be destroyed 814 839 */ 815 DLLEXPORT void trace_destroy_output(libtrace_out_t *libtrace) 816 { 817 assert(libtrace); 840 DLLEXPORT void trace_destroy_output(libtrace_out_t *libtrace) { 841 if(!libtrace) { 842 fprintf(stderr, "NULL trace passed to trace_destroy_output()\n"); 843 return; 844 } 818 845 if (libtrace->format && libtrace->format->fin_output) 819 846 libtrace->format->fin_output(libtrace); … … 825 852 DLLEXPORT int trace_flush_output(libtrace_out_t *libtrace) { 826 853 if (!libtrace) { 827 return -1; 854 fprintf(stderr, "NULL trace passed to trace_flush_output()\n"); 855 return TRACE_ERR_NULL_TRACE; 828 856 } 829 857 if (libtrace->format && libtrace->format->flush_output) { 830 858 return libtrace->format->flush_output(libtrace); 831 859 } 832 return 0; 860 861 return 0; 833 862 } 834 863 … … 897 926 packet->trace->last_packet = NULL; 898 927 } 899 928 900 929 if (packet->buf_control == TRACE_CTRL_PACKET && packet->buffer) { 901 930 free(packet->buffer); … … 958 987 DLLEXPORT int trace_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 959 988 960 assert(libtrace && "You called trace_read_packet() with a NULL libtrace parameter!\n"); 989 if (!libtrace) { 990 fprintf(stderr, "NULL trace passed to trace_read_packet()\n"); 991 return TRACE_ERR_NULL_TRACE; 992 } 993 961 994 if (trace_is_err(libtrace)) 962 995 return -1; 996 963 997 if (!libtrace->started) { 964 trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"You must call libtrace_start() before trace_read_packet() \n");998 trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"You must call libtrace_start() before trace_read_packet()"); 965 999 return -1; 966 1000 } 1001 1002 if (!packet) { 1003 trace_set_err(libtrace, TRACE_ERR_NULL_PACKET, "NULL packet passed into trace_read_packet()"); 1004 return -1; 1005 } 1006 967 1007 if (!(packet->buf_control==TRACE_CTRL_PACKET 968 1008 || packet->buf_control==TRACE_CTRL_EXTERNAL)) { 969 trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid \n");1009 trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid"); 970 1010 return -1; 971 1011 } 972 assert(packet);973 1012 974 1013 if (libtrace->format->read_packet) { … … 1052 1091 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 1053 1092 1054 assert(packet); 1055 assert(trace); 1056 1057 /* XXX Proper error handling?? */ 1058 if (buffer == NULL) 1093 if (!trace) { 1094 fprintf(stderr, "NULL trace passed into trace_prepare_packet()\n"); 1095 return TRACE_ERR_NULL_TRACE; 1096 } 1097 1098 if (!packet) { 1099 trace_set_err(trace, TRACE_ERR_NULL_TRACE, "NULL packet passed into trace_prepare_packet()"); 1059 1100 return -1; 1101 } 1102 1103 if (!buffer) { 1104 trace_set_err(trace, TRACE_ERR_NULL_BUFFER, "NULL buffer passed into trace_prepare_packet()"); 1105 return -1; 1106 } 1060 1107 1061 1108 if (!(packet->buf_control==TRACE_CTRL_PACKET || packet->buf_control==TRACE_CTRL_EXTERNAL)) { 1062 trace_set_err(trace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid \n");1109 trace_set_err(trace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid"); 1063 1110 return -1; 1064 1111 } … … 1075 1122 } 1076 1123 trace_set_err(trace, TRACE_ERR_UNSUPPORTED, 1077 "This format does not support preparing packets \n");1124 "This format does not support preparing packets"); 1078 1125 return -1; 1079 1126 … … 1087 1134 */ 1088 1135 DLLEXPORT int trace_write_packet(libtrace_out_t *libtrace, libtrace_packet_t *packet) { 1089 assert(libtrace); 1090 assert(packet); 1136 1137 if (!libtrace) { 1138 fprintf(stderr, "NULL trace passed into trace_write_packet()\n"); 1139 return TRACE_ERR_NULL_TRACE; 1140 } 1141 if (!packet) { 1142 trace_set_err_out(libtrace, TRACE_ERR_NULL_PACKET, "NULL trace passed into trace_write_packet()"); 1143 return -1; 1144 } 1091 1145 /* Verify the packet is valid */ 1092 1146 if (!libtrace->started) { 1093 1147 trace_set_err_out(libtrace,TRACE_ERR_BAD_STATE, 1094 " Trace is not started before trace_write_packet");1148 "You must call trace_start_output() before calling trace_write_packet()"); 1095 1149 return -1; 1096 1150 } … … 1117 1171 libtrace_linktype_t ltype; 1118 1172 1119 assert(packet != NULL); 1173 if (!packet) { 1174 fprintf(stderr, "NULL packet passed into trace_get_packet_buffer()\n"); 1175 return NULL; 1176 } 1120 1177 ltype = trace_get_link_type(packet); 1121 1178 … … 1149 1206 wire_len = trace_get_wire_length(packet); 1150 1207 1151 assert(cap_len >= 0); 1208 if (!(cap_len >= 0)) { 1209 fprintf(stderr, "Was expecting capture length of atleast 0 in trace_get_packet_buffer()\n"); 1210 return NULL; 1211 } 1152 1212 1153 1213 /* There is the odd corrupt packet, e.g. in IPLS II, that have … … 1341 1401 } 1342 1402 1343 assert(packet->capture_length < LIBTRACE_PACKET_BUFSIZE); 1403 if (!(packet->capture_length < LIBTRACE_PACKET_BUFSIZE)) { 1404 fprintf(stderr, "Capture length is greater than the buffer size in trace_get_capture_length()\n"); 1405 return 0; 1406 /* should we be returning ~OU here? */ 1407 } 1344 1408 1345 1409 return packet->capture_length; … … 1366 1430 } 1367 1431 1368 assert(packet->wire_length < LIBTRACE_PACKET_BUFSIZE); 1432 if (!(packet->wire_length < LIBTRACE_PACKET_BUFSIZE)) { 1433 fprintf(stderr, "Wire length is greater than the buffer size in trace_get_wire_length()\n"); 1434 return 0; 1435 /* should we be returning ~OU here? */ 1436 } 1369 1437 return packet->wire_length; 1370 1438 … … 1432 1500 1433 1501 if (!trace) { 1434 fprintf(stderr,"You called trace_event() with a NULL trace object!\n"); 1435 } 1436 assert(trace); 1437 assert(packet); 1502 fprintf(stderr, "NULL trace passed into trace_event()"); 1503 /* Return default event on error? */ 1504 return event; 1505 } 1506 if (!packet) { 1507 trace_set_err(trace, TRACE_ERR_NULL_PACKET, "NULL packet passed into trace_event()"); 1508 /* Return default event on error? */ 1509 return event; 1510 } 1438 1511 1439 1512 /* Free the last packet */ … … 1537 1610 */ 1538 1611 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 1539 assert(filter); 1612 1613 if (!packet) { 1614 fprintf(stderr, "NULL packet passed into trace_bpf_compile()"); 1615 return TRACE_ERR_NULL_PACKET; 1616 } 1617 1618 if (!filter) { 1619 trace_set_err(packet->trace, 1620 TRACE_ERR_NULL_FILTER, "Filter is NULL trace_bpf_compile()"); 1621 return -1; 1622 } 1540 1623 1541 1624 /* If this isn't a real packet, then fail */ … … 1559 1642 return -1; 1560 1643 } 1561 assert (pthread_mutex_lock(&mutex) == 0);1644 pthread_mutex_lock(&mutex); 1562 1645 /* Make sure not one bet us to this */ 1563 1646 if (filter->flag) { 1564 assert (pthread_mutex_unlock(&mutex) == 0);1565 return 1;1647 pthread_mutex_unlock(&mutex); 1648 return -1; 1566 1649 } 1567 1650 pcap=(pcap_t *)pcap_open_dead( … … 1569 1652 1500U); 1570 1653 /* build filter */ 1571 assert(pcap); 1654 if (!pcap) { 1655 trace_set_err(packet->trace, TRACE_ERR_BAD_FILTER, 1656 "Unable to open pcap_t for compiling filters trace_bpf_compile()"); 1657 return -1; 1658 } 1572 1659 if (pcap_compile( pcap, &filter->filter, filter->filterstring, 1573 1660 1, 0)) { … … 1577 1664 pcap_geterr(pcap)); 1578 1665 pcap_close(pcap); 1579 assert (pthread_mutex_unlock(&mutex) == 0);1666 pthread_mutex_unlock(&mutex); 1580 1667 return -1; 1581 1668 } 1582 1669 pcap_close(pcap); 1583 1670 filter->flag=1; 1584 assert (pthread_mutex_unlock(&mutex) == 0);1671 pthread_mutex_unlock(&mutex); 1585 1672 } 1586 1673 return 0; 1587 1674 #else 1588 assert(!"Internal bug: This should never be called when BPF not enabled");1589 1675 trace_set_err(packet->trace,TRACE_ERR_OPTION_UNAVAIL, 1590 1676 "Feature unavailable"); … … 1606 1692 #endif 1607 1693 1608 assert(filter); 1609 assert(packet); 1694 if (!packet) { 1695 fprintf(stderr, "NULL packet passed into trace_apply_filter()\n"); 1696 return TRACE_ERR_NULL_PACKET; 1697 } 1698 if (!filter) { 1699 trace_set_err(packet->trace, TRACE_ERR_NULL_FILTER, 1700 "NULL filter passed into trace_apply_filter()"); 1701 return -1; 1702 } 1610 1703 1611 1704 /* Match all non-data packets as we probably want them to pass … … 1677 1770 #endif 1678 1771 1679 assert(filter->flag); 1772 if (!filter->flag) { 1773 trace_set_err(packet->trace, TRACE_ERR_BAD_FILTER, 1774 "Bad filter passed into trace_apply_filter()"); 1775 return -1; 1776 } 1680 1777 /* Now execute the filter */ 1681 1778 #if HAVE_LLVM … … 1704 1801 libtrace_direction_t direction) 1705 1802 { 1706 assert(packet); 1803 if (!packet) { 1804 fprintf(stderr, "NULL packet passed into trace_set_direction()\n"); 1805 return (libtrace_direction_t)~0U; 1806 } 1707 1807 if (packet->trace->format->set_direction) { 1708 1808 return packet->trace->format->set_direction(packet,direction); … … 1721 1821 DLLEXPORT libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet) 1722 1822 { 1723 assert(packet); 1823 if (!packet) { 1824 fprintf(stderr, "NULL packet passed into trace_set_direction()\n"); 1825 return (libtrace_direction_t)~0U; 1826 } 1724 1827 if (packet->which_trace_start != packet->trace->startcount) { 1725 1828 return (libtrace_direction_t)~0U; … … 1858 1961 */ 1859 1962 DLLEXPORT size_t trace_set_capture_length(libtrace_packet_t *packet, size_t size) { 1860 assert(packet); 1963 if (!packet) { 1964 fprintf(stderr, "NULL packet passed into trace_set_capture_length()\n"); 1965 return ~0U; 1966 } 1861 1967 1862 1968 if (packet->trace->format->set_capture_length) { … … 1898 2004 } 1899 2005 1900 enum base_format_t trace_get_format(libtrace_packet_t *packet) 1901 { 1902 assert(packet); 2006 enum base_format_t trace_get_format(libtrace_packet_t *packet) { 2007 if (!packet) { 2008 fprintf(stderr, "NULL packet passed into trace_get_format()\n"); 2009 return TRACE_FORMAT_UNKNOWN; 2010 } 1903 2011 1904 2012 return packet->trace->format->type; … … 2102 2210 libtrace_linktype_t linktype, 2103 2211 const void *data, 2104 uint16_t len) 2105 { 2212 uint16_t len) { 2213 2214 if (!packet) { 2215 fprintf(stderr, "NULL packet passed into trace_contruct_packet()\n"); 2216 return; 2217 } 2218 /* Check a valid linktype was supplied */ 2219 if (linktype == TRACE_TYPE_UNKNOWN || linktype == TRACE_TYPE_CONTENT_INVALID) { 2220 fprintf(stderr, "Unknown or invalid linktype passed into trace_construct_packet()\n"); 2221 return; 2222 } 2223 2106 2224 size_t size; 2107 2225 static libtrace_t *deadtrace=NULL; … … 2133 2251 2134 2252 /* Now fill in the libtrace packet itself */ 2135 assert(deadtrace); 2253 if (!deadtrace) { 2254 fprintf(stderr, "Unable to create dummy trace for use within trace_construct_packet()\n"); 2255 return; 2256 } 2136 2257 packet->trace=deadtrace; 2137 2258 size=len+sizeof(hdr); … … 2165 2286 uint64_t trace_get_received_packets(libtrace_t *trace) 2166 2287 { 2167 assert(trace);2168 2288 uint64_t ret; 2289 2290 if (!trace) { 2291 fprintf(stderr, "NULL trace passed to trace_get_received_packets()\n"); 2292 /* When the number of received packets is not known we return UINT64_MAX */ 2293 return UINT64_MAX; 2294 } 2169 2295 2170 2296 if (trace->format->get_received_packets) { … … 2188 2314 uint64_t trace_get_filtered_packets(libtrace_t *trace) 2189 2315 { 2190 assert(trace); 2316 if (!trace) { 2317 fprintf(stderr, "NULL trace passed to trace_get_filtered_packets()\n"); 2318 return UINT64_MAX; 2319 } 2191 2320 int i = 0; 2192 2321 uint64_t lib_filtered = trace->filtered_packets; … … 2219 2348 uint64_t trace_get_dropped_packets(libtrace_t *trace) 2220 2349 { 2221 assert(trace); 2350 if (!trace) { 2351 fprintf(stderr, "NULL trace passed into trace_get_dropped_packets()\n"); 2352 return UINT64_MAX; 2353 } 2222 2354 uint64_t ret; 2223 2355 … … 2242 2374 uint64_t trace_get_accepted_packets(libtrace_t *trace) 2243 2375 { 2244 assert(trace); 2376 if (!trace) { 2377 fprintf(stderr, "NULL trace passed into trace_get_accepted_packets()\n"); 2378 return UINT64_MAX; 2379 } 2245 2380 int i = 0; 2246 2381 uint64_t ret = 0; … … 2260 2395 uint64_t ret = 0; 2261 2396 int i; 2262 assert(trace); 2397 if (!trace) { 2398 fprintf(stderr, "NULL trace passed into trace_get_statistics()\n"); 2399 return NULL; 2400 } 2263 2401 if (stat == NULL) { 2264 2402 if (trace->stats == NULL) … … 2266 2404 stat = trace->stats; 2267 2405 } 2268 assert(stat->magic == LIBTRACE_STAT_MAGIC && "Please use" 2269 "trace_create_statistics() to allocate statistics"); 2406 if (stat->magic != LIBTRACE_STAT_MAGIC) { 2407 trace_set_err(trace, TRACE_ERR_STAT, "Use trace_create_statistics() to allocate " 2408 "statistics prior to calling trace_get_statistics()"); 2409 return NULL; 2410 } 2270 2411 2271 2412 /* If the trace has paused or finished get the cached results */ … … 2313 2454 libtrace_stat_t *stat) 2314 2455 { 2315 assert(trace && stat); 2316 assert(stat->magic == LIBTRACE_STAT_MAGIC && "Please use" 2317 "trace_create_statistics() to allocate statistics"); 2456 if (!trace) { 2457 fprintf(stderr, "NULL trace passed into trace_get_thread_statistics()\n"); 2458 return; 2459 } 2460 if (!stat) { 2461 trace_set_err(trace, TRACE_ERR_STAT, "NULL statistics structure passed into " 2462 "trace_get_thread_statistics()"); 2463 return; 2464 } 2465 if (stat->magic != LIBTRACE_STAT_MAGIC) { 2466 trace_set_err(trace, TRACE_ERR_STAT, "Use trace_create_statistics() to " 2467 "allocate statistics prior to calling trace_get_thread_statistics()"); 2468 return; 2469 } 2318 2470 stat->reserved1 = 0; 2319 2471 stat->reserved2 = 0; … … 2328 2480 trace->format->get_thread_statistics(trace, t, stat); 2329 2481 } 2330 return;2331 2482 } 2332 2483 … … 2348 2499 void trace_subtract_statistics(const libtrace_stat_t *a, const libtrace_stat_t *b, 2349 2500 libtrace_stat_t *c) { 2350 assert(a->magic == LIBTRACE_STAT_MAGIC && "Please use" 2351 "trace_create_statistics() to allocate statistics"); 2352 assert(b->magic == LIBTRACE_STAT_MAGIC && "Please use" 2353 "trace_create_statistics() to allocate statistics"); 2354 assert(c->magic == LIBTRACE_STAT_MAGIC && "Please use" 2355 "trace_create_statistics() to allocate statistics"); 2501 2502 if (a->magic != LIBTRACE_STAT_MAGIC 2503 || b->magic != LIBTRACE_STAT_MAGIC 2504 || c->magic != LIBTRACE_STAT_MAGIC) { 2505 fprintf(stderr, "Use trace_create_statistics() to allocate statistics prior to " 2506 "calling trace_subtract_statistics()\n"); 2507 return; 2508 } 2356 2509 2357 2510 #define X(x) \ … … 2368 2521 void trace_add_statistics(const libtrace_stat_t *a, const libtrace_stat_t *b, 2369 2522 libtrace_stat_t *c) { 2370 assert(a->magic == LIBTRACE_STAT_MAGIC && "Please use" 2371 "trace_create_statistics() to allocate statistics"); 2372 assert(b->magic == LIBTRACE_STAT_MAGIC && "Please use" 2373 "trace_create_statistics() to allocate statistics"); 2374 assert(c->magic == LIBTRACE_STAT_MAGIC && "Please use" 2375 "trace_create_statistics() to allocate statistics"); 2523 if (a->magic != LIBTRACE_STAT_MAGIC 2524 || b->magic != LIBTRACE_STAT_MAGIC 2525 || c->magic != LIBTRACE_STAT_MAGIC) { 2526 fprintf(stderr, "Use trace_create_statistics() to allocate statistics prior to " 2527 "calling trace_add_statistics()\n"); 2528 return; 2529 } 2376 2530 2377 2531 #define X(x) \ … … 2387 2541 2388 2542 int trace_print_statistics(const libtrace_stat_t *s, FILE *f, const char *format) { 2389 assert(s->magic == LIBTRACE_STAT_MAGIC && "Please use" 2390 "trace_create_statistics() to allocate statistics"); 2543 if (s->magic != LIBTRACE_STAT_MAGIC) { 2544 fprintf(stderr, "Use trace_create_statistics() to allocate statistics prior to " 2545 "calling trace_print_statistics\n"); 2546 return TRACE_ERR_STAT; 2547 } 2391 2548 if (format == NULL) 2392 2549 format = "%s: %"PRIu64"\n"; … … 2427 2584 2428 2585 void register_format(struct libtrace_format_t *f) { 2429 assert(f->next==NULL); /* Can't register a format twice */ 2586 if (f->next != NULL) { 2587 fprintf(stderr, "You cannot register a format twice in register_format()"); 2588 return; 2589 } 2430 2590 f->next=formats_list; 2431 2591 formats_list=f; -
lib/trace_parallel.c
r37ee856 r2193905 271 271 DLLEXPORT bool trace_has_reporter(libtrace_t * libtrace) 272 272 { 273 assert(libtrace->state != STATE_NEW); 273 if (!(libtrace->state != STATE_NEW)) { 274 trace_set_err(libtrace, TRACE_ERR_BAD_STATE, "Cannot check reporter for the current state in trace_has_reporter()"); 275 return false; 276 } 274 277 return libtrace->reporter_thread.type == THREAD_REPORTER && libtrace->reporter_cbs; 275 278 } … … 368 371 static inline bool trace_supports_parallel(libtrace_t *trace) 369 372 { 370 assert(trace); 371 assert(trace->format); 373 if (!trace) { 374 fprintf(stderr, "NULL trace passed into trace_supports_parallel()\n"); 375 return false; 376 } 377 if (!trace->format) { 378 trace_set_err(trace, TRACE_ERR_BAD_FORMAT, 379 "NULL capture format associated with trace in trace_supports_parallel()"); 380 return false; 381 } 372 382 if (trace->format->pstart_input) 373 383 return true; … … 400 410 return &libtrace->perpkt_threads[i]; 401 411 } 402 return NULL;412 pthread_exit(NULL); 403 413 } 404 414 … … 490 500 trace_fin_packet(*packet); 491 501 } else { 492 assert((*packet)->error == READ_TICK); 502 if ((*packet)->error != READ_TICK) { 503 trace_set_err(trace, TRACE_ERR_BAD_STATE, 504 "dispatch_packet() called with invalid 'packet'"); 505 return -1; 506 } 493 507 libtrace_generic_t data = {.uint64 = trace_packet_get_order(*packet)}; 494 508 send_message(trace, t, MESSAGE_TICK_COUNT, data, t); … … 533 547 } else { 534 548 /* Break early */ 535 assert(ret == READ_MESSAGE); 549 if (ret != READ_MESSAGE) { 550 trace_set_err(trace, TRACE_ERR_UNKNOWN_OPTION, 551 "dispatch_packets() called with at least one invalid packet"); 552 return -1; 553 } 536 554 return READ_MESSAGE; 537 555 } … … 583 601 } else if (ret != READ_MESSAGE) { 584 602 /* Ignore messages we pick these up next loop */ 585 assert (ret == READ_EOF || ret == READ_ERROR); 603 if (!(ret == READ_EOF || ret == READ_ERROR)) { 604 trace_set_err(trace, TRACE_ERR_PAUSE_PTHREAD, 605 "Error pausing processing thread in trace_perpkt_thread_pause()"); 606 return -1; 607 } 586 608 /* Verify no packets are remaining */ 587 609 /* TODO refactor this sanity check out!! */ … … 589 611 ASSERT_RET(trace->pread(trace, t, &packet, 1), <= 0); 590 612 // No packets after this should have any data in them 591 assert(packet->error <= 0); 613 if (packet->error > 0) { 614 trace_set_err(trace, TRACE_ERR_BAD_PACKET, "Bogus data in " 615 "libtrace ring buffer after pausing perpkt thread"); 616 return -1; 617 } 592 618 } 593 619 libtrace_ocache_free(&trace->packet_freelist, (void **) &packet, 1, 1); … … 625 651 ASSERT_RET(pthread_mutex_lock(&trace->libtrace_lock), == 0); 626 652 t = get_thread_table(trace); 627 assert(t); 653 if (!t) { 654 trace_set_err(trace, TRACE_ERR_THREAD, "Unable to get thread table in perpkt_threads_entry()"); 655 pthread_exit(NULL); 656 } 628 657 if (trace->state == STATE_ERROR) { 629 658 thread_change_state(trace, t, THREAD_FINISHED, false); … … 666 695 goto error; 667 696 } 668 assert(ret == 1); 697 if (ret != 1) { 698 fprintf(stderr, "Unknown error pausing thread in perpkt_threads_entry()\n"); 699 pthread_exit(NULL); 700 } 669 701 continue; 670 702 case MESSAGE_DO_STOP: // This is internal … … 689 721 } 690 722 if (!trace->pread) { 691 assert(packets[0]); 723 if (!packets[0]) { 724 fprintf(stderr, "Unable to read into NULL packet structure\n"); 725 pthread_exit(NULL); 726 } 692 727 nb_packets = trace_read_packet(trace, packets[0]); 693 728 packets[0]->error = nb_packets; … … 781 816 int pkt_skipped = 0; 782 817 783 assert(trace_has_dedicated_hasher(trace)); 818 if (!trace_has_dedicated_hasher(trace)) { 819 fprintf(stderr, "Trace does not have hasher associated with it in hasher_entry()\n"); 820 pthread_exit(NULL); 821 } 784 822 /* Wait until all threads are started and objects are initialised (ring buffers) */ 785 823 ASSERT_RET(pthread_mutex_lock(&trace->libtrace_lock), == 0); 786 824 t = &trace->hasher_thread; 787 assert(t->type == THREAD_HASHER && pthread_equal(pthread_self(), t->tid)); 825 if (!(t->type == THREAD_HASHER && pthread_equal(pthread_self(), t->tid))) { 826 fprintf(stderr, "Incorrect thread type or non matching thread IDs in hasher_entry()\n"); 827 pthread_exit(NULL); 828 } 829 788 830 if (trace->state == STATE_ERROR) { 789 831 thread_change_state(trace, t, THREAD_FINISHED, false); … … 803 845 if (!pkt_skipped) 804 846 libtrace_ocache_alloc(&trace->packet_freelist, (void **) &packet, 1, 1); 805 assert(packet); 847 if (!packet) { 848 fprintf(stderr, "Hasher thread was unable to get a fresh packet from the " 849 "object cache\n"); 850 pthread_exit(NULL); 851 } 806 852 807 853 // Check for messages that we expect MESSAGE_DO_PAUSE, (internal messages only) … … 821 867 case MESSAGE_DO_STOP: 822 868 /* Either FINISHED or FINISHING */ 823 assert(trace->started == false); 869 if (!(trace->started == false)) { 870 fprintf(stderr, "STOP message received by hasher, but " 871 "trace is still active\n"); 872 pthread_exit(NULL); 873 } 824 874 /* Mark the current packet as EOF */ 825 875 packet->error = 0; … … 860 910 } 861 911 pkt_skipped = 0; 862 } else {863 assert(!"Dropping a packet!!");864 pkt_skipped = 1; // Reuse that packet no one read it865 912 } 866 913 } … … 990 1037 sent once*/ 991 1038 if (packets[i]->error != READ_MESSAGE) { 992 assert(t->format_data == NULL);993 1039 t->format_data = packets[i]; 994 1040 } … … 1150 1196 break; 1151 1197 case MESSAGE_DO_PAUSE: 1152 assert(trace->combiner.pause); 1153 trace->combiner.pause(trace, &trace->combiner); 1198 if(trace->combiner.pause) { 1199 trace->combiner.pause(trace, &trace->combiner); 1200 } 1154 1201 send_message(trace, t, MESSAGE_PAUSING, 1155 1202 (libtrace_generic_t) {0}, t); … … 1173 1220 thread_change_state(trace, &trace->reporter_thread, THREAD_FINISHED, true); 1174 1221 print_memory_stats(); 1175 return NULL;1222 pthread_exit(NULL); 1176 1223 } 1177 1224 … … 1209 1256 libtrace_message_t msg; 1210 1257 libtrace_message_queue_get(&t->messages, &msg); 1211 assert(msg.code == MESSAGE_DO_STOP); 1258 if (msg.code != MESSAGE_DO_STOP) { 1259 fprintf(stderr, "Unexpected message code in keepalive_entry()\n"); 1260 pthread_exit(NULL); 1261 } 1212 1262 goto done; 1213 1263 } … … 1223 1273 1224 1274 thread_change_state(trace, t, THREAD_FINISHED, true); 1225 return NULL;1275 pthread_exit(NULL); 1226 1276 } 1227 1277 … … 1273 1323 return READ_MESSAGE; 1274 1324 } else { 1275 assert(!"trace_delay_packet: Unexpected return from select"); 1325 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Unexpected return from select in delay_tracetime()"); 1326 return -1; 1276 1327 } 1277 1328 } … … 1325 1376 size_t nb_packets) { 1326 1377 int i; 1327 assert(nb_packets); 1328 assert(libtrace && "libtrace is NULL in trace_read_packet()"); 1378 if (!libtrace) { 1379 fprintf(stderr, "NULL trace passed into trace_read_packet()\n"); 1380 return TRACE_ERR_NULL_TRACE; 1381 } 1382 if (nb_packets <= 0) { 1383 trace_set_err(libtrace, TRACE_ERR_NULL, 1384 "nb_packets must be greater than zero in trace_pread_packet_wrapper()"); 1385 return -1; 1386 } 1329 1387 if (trace_is_err(libtrace)) 1330 1388 return -1; … … 1338 1396 int ret; 1339 1397 for (i = 0; i < (int) nb_packets; ++i) { 1340 assert(i[packets]); 1398 if (!i[packets]) { 1399 trace_set_err(libtrace, TRACE_ERR_BAD_STATE, "NULL packets in " 1400 "trace_pread_packet_wrapper()"); 1401 return -1; 1402 } 1341 1403 if (!(packets[i]->buf_control==TRACE_CTRL_PACKET || 1342 1404 packets[i]->buf_control==TRACE_CTRL_EXTERNAL)) { … … 1397 1459 } 1398 1460 1399 assert(libtrace_parallel); 1400 assert(!libtrace->perpkt_thread_states[THREAD_RUNNING]); 1461 if (!libtrace_parallel) { 1462 trace_set_err(libtrace, TRACE_ERR_THREAD, "Trace_prestart() has been called on a " 1463 "non-parallel libtrace input?"); 1464 return -1; 1465 } 1466 if (libtrace->perpkt_thread_states[THREAD_RUNNING]) { 1467 trace_set_err(libtrace, TRACE_ERR_THREAD, "Cannot restart a parallel libtrace input " 1468 "while it is still running"); 1469 return -1; 1470 } 1401 1471 1402 1472 /* Reset first packets */ 1403 1473 pthread_spin_lock(&libtrace->first_packets.lock); 1404 1474 for (i = 0; i < libtrace->perpkt_thread_count; ++i) { 1405 assert(!!libtrace->perpkt_threads[i].recorded_first == !!libtrace->first_packets.packets[i].packet);1406 1475 if (libtrace->first_packets.packets[i].packet) { 1407 1476 trace_destroy_packet(libtrace->first_packets.packets[i].packet); … … 1413 1482 } 1414 1483 } 1415 assert(libtrace->first_packets.count == 0); 1484 if (libtrace->first_packets.count != 0) { 1485 trace_set_err(libtrace, TRACE_ERR_THREAD, "Expected a first packets count of 0 in trace_pstart()"); 1486 return -1; 1487 } 1416 1488 libtrace->first_packets.first = 0; 1417 1489 pthread_spin_unlock(&libtrace->first_packets.lock); … … 1447 1519 1448 1520 libtrace->reporter_cbs = trace_create_callback_set(); 1449 memcpy(libtrace->reporter_cbs, reporter_cbs, 1521 memcpy(libtrace->reporter_cbs, reporter_cbs, 1450 1522 sizeof(libtrace_callback_set_t)); 1451 1523 } … … 1552 1624 #endif 1553 1625 int ret; 1554 assert(t->type == THREAD_EMPTY); 1626 if (t->type != THREAD_EMPTY) { 1627 trace_set_err(trace, TRACE_ERR_THREAD, 1628 "Expected thread type of THREAD_EMPTY in trace_start_thread()"); 1629 return -1; 1630 } 1555 1631 t->trace = trace; 1556 1632 t->ret = NULL; … … 1559 1635 t->state = THREAD_RUNNING; 1560 1636 1561 assert(name); 1637 if (!name) { 1638 trace_set_err(trace, TRACE_ERR_THREAD, "NULL thread name in trace_start_thread()"); 1639 return -1; 1640 } 1562 1641 1563 1642 #ifdef __linux__ … … 1682 1761 char name[24]; 1683 1762 sigset_t sig_before, sig_block_all; 1684 assert(libtrace); 1763 if (!libtrace) { 1764 fprintf(stderr, "NULL trace passed to trace_pstart()\n"); 1765 return -1; 1766 } 1685 1767 1686 1768 ASSERT_RET(pthread_mutex_lock(&libtrace->libtrace_lock), == 0); … … 1904 1986 ASSERT_RET(pthread_mutex_lock(&libtrace->libtrace_lock), == 0); 1905 1987 libtrace_change_state(libtrace, STATE_NEW, false); 1906 assert(libtrace->perpkt_thread_states[THREAD_RUNNING] == 0); 1988 if (libtrace->perpkt_thread_states[THREAD_RUNNING] != 0) { 1989 trace_set_err(libtrace, TRACE_ERR_THREAD, "Expected 0 running threads in trace_pstart()"); 1990 return -1; 1991 } 1907 1992 libtrace->perpkt_thread_states[THREAD_FINISHED] = 0; 1908 1993 cleanup_started: … … 1996 2081 libtrace_thread_t *t; 1997 2082 int i; 1998 assert(libtrace); 2083 if (!libtrace) { 2084 fprintf(stderr, "NULL trace passed into trace_ppause()\n"); 2085 return TRACE_ERR_NULL_TRACE; 2086 } 1999 2087 2000 2088 t = get_thread_table(libtrace); … … 2129 2217 int i, err; 2130 2218 libtrace_message_t message = {0, {.uint64=0}, NULL}; 2131 assert(libtrace); 2219 if (!libtrace) { 2220 fprintf(stderr, "NULL trace passed into trace_pstop()\n"); 2221 return TRACE_ERR_NULL_TRACE; 2222 } 2132 2223 2133 2224 // Ensure all threads have paused and the underlying trace format has … … 2227 2318 // the producer (or any other threads) don't block. 2228 2319 libtrace_packet_t * packet; 2229 assert(libtrace->perpkt_threads[i].state == THREAD_FINISHED); 2320 if (libtrace->perpkt_threads[i].state != THREAD_FINISHED) { 2321 trace_set_err(libtrace, TRACE_ERR_THREAD_STATE, 2322 "Expected processing thread state to be THREAD_FINISHED in trace_join()"); 2323 return; 2324 } 2230 2325 while(libtrace_ringbuffer_try_read(&libtrace->perpkt_threads[i].rbuffer, (void **) &packet)) 2231 2326 if (packet) // This could be NULL iff the perpkt finishes early … … 2236 2331 if (trace_has_dedicated_hasher(libtrace)) { 2237 2332 pthread_join(libtrace->hasher_thread.tid, NULL); 2238 assert(libtrace->hasher_thread.state == THREAD_FINISHED); 2333 if (libtrace->hasher_thread.state != THREAD_FINISHED) { 2334 trace_set_err(libtrace, TRACE_ERR_THREAD_STATE, 2335 "Expected hasher thread state to be THREAD_FINISHED in trace_join()"); 2336 return; 2337 } 2239 2338 } 2240 2339 … … 2248 2347 trace_destroy_packet(packet); 2249 2348 if (trace_has_dedicated_hasher(libtrace)) { 2250 assert(libtrace_ringbuffer_is_empty(&libtrace->perpkt_threads[i].rbuffer)); 2349 if (!libtrace_ringbuffer_is_empty(&libtrace->perpkt_threads[i].rbuffer)) { 2350 trace_set_err(libtrace, TRACE_ERR_THREAD, 2351 "Expected processing threads ring buffers to be empty in trace_join()"); 2352 return; 2353 } 2251 2354 libtrace_ringbuffer_destroy(&libtrace->perpkt_threads[i].rbuffer); 2252 2355 } … … 2256 2359 if (trace_has_reporter(libtrace)) { 2257 2360 pthread_join(libtrace->reporter_thread.tid, NULL); 2258 assert(libtrace->reporter_thread.state == THREAD_FINISHED); 2361 if (libtrace->reporter_thread.state != THREAD_FINISHED) { 2362 trace_set_err(libtrace, TRACE_ERR_THREAD_STATE, 2363 "Expected reporting thread state to be THREAD_FINISHED in trace_join()"); 2364 return; 2365 } 2259 2366 } 2260 2367 … … 2363 2470 res.key = key; 2364 2471 res.value = value; 2365 assert(libtrace->combiner.publish); 2472 if (!libtrace->combiner.publish) { 2473 fprintf(stderr, "Combiner has no publish method -- can not publish results!\n"); 2474 return; 2475 } 2366 2476 libtrace->combiner.publish(libtrace, t->perpkt_num, &libtrace->combiner, &res); 2367 2477 return; … … 2515 2625 /* Note update documentation on trace_set_configuration */ 2516 2626 static void config_string(struct user_configuration *uc, char *key, size_t nkey, char *value, size_t nvalue) { 2517 assert(key); 2518 assert(value); 2519 assert(uc); 2627 if (!key) { 2628 fprintf(stderr, "NULL key passed to config_string()\n"); 2629 return; 2630 } 2631 if (!value) { 2632 fprintf(stderr, "NULL value passed to config_string()\n"); 2633 return; 2634 } 2635 if (!uc) { 2636 fprintf(stderr, "NULL uc (user_configuration) passed to config_string()\n"); 2637 return; 2638 } 2520 2639 if (strncmp(key, "cache_size", nkey) == 0 2521 2640 || strncmp(key, "cs", nkey) == 0) { … … 2564 2683 char value[100]; 2565 2684 char *dup; 2566 assert(str); 2567 assert(trace); 2685 if (!trace) { 2686 fprintf(stderr, "NULL trace passed into trace_set_configuration()\n"); 2687 return TRACE_ERR_NULL_TRACE; 2688 } 2689 if (!str) { 2690 trace_set_err(trace, TRACE_ERR_CONFIG, "NULL configuration string passed to trace_set_configuration()"); 2691 return -1; 2692 } 2568 2693 2569 2694 if (!trace_is_configurable(trace)) return -1; … … 2576 2701 config_string(&trace->config, key, sizeof(key), value, sizeof(value)); 2577 2702 } else { 2578 fprintf(stderr, "Error parsing option %s\n", pch);2703 fprintf(stderr, "Error: parsing option %s\n", pch); 2579 2704 } 2580 2705 pch = strtok (NULL," ,.-"); … … 2601 2726 2602 2727 DLLEXPORT void trace_free_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 2603 assert(packet); 2728 if (!packet) { 2729 trace_set_err(libtrace, TRACE_ERR_NULL_PACKET, 2730 "NULL packet passed to trace_free_packet()"); 2731 return; 2732 } 2604 2733 /* Always release any resources this might be holding */ 2605 2734 trace_fin_packet(packet); … … 2632 2761 return &libtrace->format->info; 2633 2762 else 2634 return NULL;2635 } 2763 pthread_exit(NULL); 2764 } -
tools/tracereplay/tracereplay.c
r8a12a49 rd7d3267 104 104 105 105 pkt_buffer = trace_get_packet_buffer(packet,&linktype,&remaining); 106 /* Check if the linktype was found, if not skip this packet */ 107 if (linktype == TRACE_TYPE_UNKNOWN || linktype == TRACE_TYPE_CONTENT_INVALID) { 108 return NULL; 109 } 110 106 111 remaining = 0; 107 112 new_packet = trace_create_packet();
Note: See TracChangeset
for help on using the changeset viewer.