type
stringclasses
5 values
content
stringlengths
9
163k
functions
void goodB2G2() { int data; /* Initialize data */ data = -1; if(globalFive==5) { { #ifdef _WIN32 WSADATA wsaData; int wsaDataInit = 0; #endif int recvResult; struct sockaddr_in service; SOCKET listenSocket = INVALID_SO...
functions
_WIN32 if (wsaDataInit) { WSACleanup(); }
functions
void goodG2B1() { int data; /* Initialize data */ data = -1; if(globalFive!=5) { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ printLine("Benign, fixed string"); }
functions
void goodG2B2() { int data; /* Initialize data */ data = -1; if(globalFive==5) { /* FIX: Use a value greater than 0, but less than 10 to avoid attempting to * access an index of the array in the sink that is out-of-bounds */ data = 7; }
functions
void CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_14_good() { goodB2G1(); goodB2G2(); goodG2B1(); goodG2B2(); }
main
int main(int argc, char * argv[]) { /* seed randomness */ srand( (unsigned)time(NULL) ); #ifndef OMITGOOD printLine("Calling good()..."); CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_14_good(); printLine("Finished good()"); #endif /* OMITGOOD */ #ifndef OMITBAD printLine("...
includes
#include <stdio.h>
includes
#include <string.h>
includes
#include <stdlib.h>
defines
#define BSIZE 2880 * 512
functions
write if(argi != -1){ sector = strtol(argv[argi], NULL, 10); if(sector > 2879){ perror("Error: the maximum sector is 2879"); return 2; }
functions
int getarg(int argc, char* argv[], char* arg){ int i; for(i = 0; i < argc; i++){ if(strcmp(argv[i], arg) == 0){ return i + 1; }
functions
int fsize(char fname[]){ int t; FILE *file; file = fopen(fname, "r"); fseek(file, 0, SEEK_END); t = ftell(file); fclose(file); return t; }
functions
void erase(char *buff, int size){ int i; for(i = 0; i < size; i++){ buff[i] = 0; }
functions
void showhelp(){ printf("Use: imgw [options] binary\n\n"); printf(" -h Show this help message\n"); printf(" -s sector Set the sector for write the binary file. Default is 0\n"); printf(" -n If defined, create a new image file. Erasing the image file if exist\n"); printf(" -o output S...
main
int main(int argc, char* argv[]){ int fs, ind, argi, sector = 0; char buffer[BSIZE], imgname[512]; FILE *img; FILE *bin; erase(buffer, BSIZE); printf("IMG Writer - Program for write image files\n"); printf(" Programmed by Luiz Felipe\n"); printf(" GitHub: https://github.com/Silva97/\n\n"); if...
defines
#define ANCHOR_TEMPLATE "id%03d"
defines
#define ANCHOR_TEMPLATE_LENGTH 16
functions
void yaml_emitter_delete_document_and_anchors(yaml_emitter_t *emitter) { int index; if (!emitter->anchors) { yaml_document_delete(emitter->document); emitter->document = NULL; return; }
functions
void yaml_emitter_anchor_node(yaml_emitter_t *emitter, int index) { yaml_node_t *node = emitter->document->nodes.start + index - 1; yaml_node_item_t *item; yaml_node_pair_t *pair; emitter->anchors[index-1].references ++; if (emitter->anchors[index-1].references == 1) { switch (node->type) ...
functions
else if (emitter->anchors[index-1].references == 2) { emitter->anchors[index-1].anchor = (++ emitter->last_anchor_id); }
functions
int yaml_emitter_dump_node(yaml_emitter_t *emitter, int index) { yaml_node_t *node = emitter->document->nodes.start + index - 1; int anchor_id = emitter->anchors[index-1].anchor; yaml_char_t *anchor = NULL; if (anchor_id) { anchor = yaml_emitter_generate_anchor(emitter, anchor_id); if (...
functions
int yaml_emitter_dump_alias(yaml_emitter_t *emitter, yaml_char_t *anchor) { yaml_event_t event; yaml_mark_t mark = { 0, 0, 0 }
functions
int yaml_emitter_dump_scalar(yaml_emitter_t *emitter, yaml_node_t *node, yaml_char_t *anchor) { yaml_event_t event; yaml_mark_t mark = { 0, 0, 0 }
functions
int yaml_emitter_dump_sequence(yaml_emitter_t *emitter, yaml_node_t *node, yaml_char_t *anchor) { yaml_event_t event; yaml_mark_t mark = { 0, 0, 0 }
functions
int yaml_emitter_dump_mapping(yaml_emitter_t *emitter, yaml_node_t *node, yaml_char_t *anchor) { yaml_event_t event; yaml_mark_t mark = { 0, 0, 0 }
includes
#include <assert.h>
includes
#include <ctype.h>
includes
#include <stdbool.h>
includes
#include <stdio.h>
includes
#include <stdlib.h>
includes
#include <string.h>
defines
#define skip_spaces() while (isspace(*data)) ++data
functions
bool check(bool full, char *input, const char *expected) { static char buffer[2048]; char *actual; if (full) g_data = input; else { snprintf(buffer, sizeof(buffer), "void t() {%s}
functions
void parse_tasks(char *data) { static char *group_name, *test_name; static char *code, *tree; static bool is_full; /* [group name] test name* ========= code ~~~~~~~~~ tree ~~~~~~~~~ */ for (;;) { skip_spaces(); if (!*...
functions
void test_parser(void) { size_t size; char *data; FILE *fp = fopen("test/test-parser.txt", "r"); assert(fp); // Determine the size. fseek(fp, 0, SEEK_END); size = ftell(fp); fseek(fp, 0, SEEK_SET); // Read all content from the file. data = xmalloc(size + 1); fread(data, 1,...
includes
#include <stdlib.h>
includes
#include <stdio.h>
includes
#include <sys/types.h>
includes
#include <sys/socket.h>
includes
#include <netinet/in.h>
includes
#include <netdb.h>
includes
#include <unistd.h>
includes
#include <inttypes.h>
includes
#include <string.h>
includes
#include <arpa/inet.h>
includes
#include <pthread.h>
main
int main(int argc, char ** argv) { char* server_port = "1234"; char* thread_number = "2"; int sockfd; int o; while ((o = getopt (argc, argv, "p:n:d:h")) != -1) { switch(o){ case 'p': server_port = optarg; ...
includes
#include <math.h>
includes
#include <unistd.h>
includes
#include <float.h>
includes
#include <stddef.h>
includes
#include <sys/uio.h>
includes
#include <sys/socket.h>
defines
#define _GNU_SOURCE
defines
#define MAX_PACKET_SIZE 512
functions
void statsd_run_recvmmsg(struct brubeck_statsd *statsd, int sock) { const unsigned int SIM_PACKETS = statsd->mmsg_count; struct brubeck_server *server = statsd->sampler.server; struct brubeck_statsd_msg msg; struct brubeck_metric *metric; unsigned int i; struct iovec iovecs[SIM_PACKETS]; struct mmsghdr msgs[SI...
functions
void statsd_run_recvmsg(struct brubeck_statsd *statsd, int sock) { struct brubeck_server *server = statsd->sampler.server; struct brubeck_statsd_msg msg; struct brubeck_metric *metric; char buffer[MAX_PACKET_SIZE]; struct sockaddr_in reporter; socklen_t reporter_len = sizeof(reporter); memset(&reporter, 0, re...
functions
int brubeck_statsd_msg_parse(struct brubeck_statsd_msg *msg, char *buffer, size_t length) { char *end = buffer + length; *end = '\0'; /** * Message key: all the string until the first ':' * * gaugor:333|g * ^^^^^^ */ { msg->key = buffer; msg->key_len = 0; while (*buffer != ':' && *buffer ...
functions
SO_REUSEPORT if (sock < 0) { sock = brubeck_sampler_socket(&statsd->sampler, 1); }
functions
HAVE_RECVMMSG if (statsd->mmsg_count > 1) { statsd_run_recvmmsg(statsd, sock); return NULL; }
functions
void run_worker_threads(struct brubeck_statsd *statsd) { unsigned int i; statsd->workers = xmalloc(statsd->worker_count * sizeof(pthread_t)); for (i = 0; i < statsd->worker_count; ++i) { pthread_create(&statsd->workers[i], NULL, &statsd__thread, statsd); }
functions
void shutdown_sampler(struct brubeck_sampler *sampler) { struct brubeck_statsd *statsd = (struct brubeck_statsd *)sampler; size_t i; for (i = 0; i < statsd->worker_count; ++i) { pthread_cancel(statsd->workers[i]); }
includes
#include <signal.h>
defines
#define LCD_DIV_64 5
defines
#define partstNUM_LEDS ( ( unsigned char ) 6 )
defines
#define partstSEGMENTS_ON ( ( unsigned char ) 0x0f )
defines
#define partstSEGMENTS_OFF ( ( unsigned char ) 0x00 )
defines
#define partstON_BOARD_LED ( ( unsigned portBASE_TYPE ) 10 )
defines
#define mainON_BOARD_LED_BIT ( ( unsigned char ) 0x01 )
functions
void vParTestInitialise( void ) { /* Initialise the LCD hardware. */ /* Used for the onboard LED. */ P1DIR = 0x01; // Setup Basic Timer for LCD operation BTCTL = (LCD_DIV_64+0x23); // Setup port functions P1SEL = 0x32; P2SEL = 0x00; P3SEL = 0x00; P4SEL = 0xFC; P5SEL = 0xFF; /* Initialise all segments t...
functions
void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue ) { /* Set or clear the output [in this case show or hide the '*' character. */ if( uxLED < ( portBASE_TYPE ) partstNUM_LEDS ) { vTaskSuspendAll(); { if( xValue ) { /* Turn on the segments required to show the '*'. */ *(...
functions
void vParTestToggleLED( unsigned portBASE_TYPE uxLED ) { if( uxLED < ( portBASE_TYPE ) partstNUM_LEDS ) { vTaskSuspendAll(); { /* If the '*' is already showing - hide it. If it is not already showing then show it. */ if( *( ucRHSSegments[ uxLED ] ) ) { *( ucRHSSegments[ uxLED ] ) = partstSEGMENTS...
functions
void prvToggleOnBoardLED( void ) { static unsigned short sState = pdFALSE; /* Toggle the state of the single genuine on board LED. */ if( sState ) { P1OUT |= mainON_BOARD_LED_BIT; }
includes
#include<stdio.h>
includes
#include<stdlib.h>
includes
#include<ctype.h>
includes
#include<time.h>
includes
#include<string.h>
defines
#define MAX_STR_LEN 25
functions
void start_timer(Timer *t) { struct timeval tp; int rtn; rtn=gettimeofday(&tp, NULL); t->start = (double)tp.tv_sec+(1.e-6)*tp.tv_usec; }
functions
double get_time_diff(Timer *t) { return t->end - t->start; }
functions
void end_timer(Timer *t) { struct timeval tp; int rtn; rtn=gettimeofday(&tp, NULL); t->end = (double)tp.tv_sec+(1.e-6)*tp.tv_usec; }
functions
void destroy(Data* list) { }
functions
void push(Data **head, char *name) { }
functions
void display(Data *list) { }
functions
int length(Data* list) { int count = 0; Data* current = list; while(current) { current = current->nextData; ++count; }
functions
void split_in_half(Data *source, Data **frontRef, Data** backRef) { }
functions
void move_node(Data** destRef, Data** sourceRef) { Data* newData = *sourceRef; *sourceRef = newData->nextData; newData->nextData = *destRef; *destRef = newData; }
functions
void merge_sort(Data **list) { }
main
int main (int argc, char **argv) { /* * Error checking the number of passed in parameters * */ if (argc < 3) { printf("Not enough parameters bub!\n"); exit(0); }
functions
real_T rt_NormalRand(uint32_T *seed) { real_T sr, si, t; do { sr = (2.0 * rt_Urand(seed)) - 1.0; si = (2.0 * rt_Urand(seed)) - 1.0; t = (sr * sr) + (si * si); }
defines
#define DNS_MAX_HOST_NAME_LEN 128
functions
int parse_next_query(void *data, int size, dns_query_t *query) { int len; int lables; uint8_t *ptr; len = 0; lables = 0; ptr = (uint8_t *)data; while (true) { uint8_t lable_len; if (size <= 0) return -1; lable_len = *ptr++; size--; if (lable_len == 0) break; if (lables > 0) { if (len == DNS_M...
functions
void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port) { int len; dns_header_t *header; static dns_query_t query; struct pbuf *out; ip_addr_t host_addr; dns_answer_t *answer; if (p->len <= sizeof(dns_header_t)) goto error; header = (dns_header_t *)p->payload; if ...
functions
err_t dnserv_init(ip_addr_t *bind, uint16_t port, dns_query_proc_t qp) { err_t err; udp_init(); dnserv_free(); pcb = udp_new(); if (pcb == NULL) return ERR_MEM; err = udp_bind(pcb, bind, port); if (err != ERR_OK) { dnserv_free(); return err; }
functions
void dnserv_free() { if (pcb == NULL) return; udp_remove(pcb); pcb = NULL; }