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_SOCKET; SOCKET acceptSocket = INVALID_SOCKET; char inputBuffer[CHAR_ARRAY_SIZE]; do { #ifdef _WIN32 if (WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) { break; }
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("Calling bad()..."); CWE122_Heap_Based_Buffer_Overflow__c_CWE129_listen_socket_14_bad(); printLine("Finished bad()"); #endif /* OMITBAD */ return 0; }
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 Set the name of the image file for write. Default is 'disk.img'\n"); printf(" binary Binary file for write in the image file\n"); }
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(getarg(argc, argv, "-h") != -1 || argc == 1){ showhelp(); return 0; }
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) { case YAML_SEQUENCE_NODE: for (item = node->data.sequence.items.start; item < node->data.sequence.items.top; item ++) { yaml_emitter_anchor_node(emitter, *item); }
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 (!anchor) return 0; }
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 (!*data) break; assert(*data == '[' && "Expected group."); group_name = ++data; data = strchr(data, ']'); assert(data && "Unfinished group name."); *(data++) = '\0'; group(group_name); for (;;) { skip_spaces(); if (!*data || *data == '[') break; assert(data && "Expected test."); test_name = data; data = strchr(data, '\n'); assert(data && "Unfinished test name."); if (data[-1] == '*') { is_full = false; data[-1] = '\0'; }
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, size, fp); fclose(fp); data[size] = '\0'; parse_tasks(data); free(data); }
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; break; case 'n': thread_number = optarg; break; case 'd': verbose_print = 1; kvprintf("[!] verbose mode enabled\n"); break; case 'h': printf("Command line args:\n" "\t -p port\n" "\t -n number of threads\n" "\t -d verbose output\n" "\t -h this menu\n"); break; case '?': if(optopt == 'p') { fprintf (stderr, "Option %c requires an argument.\n", optopt); }
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[SIM_PACKETS]; memset(msgs, 0x0, sizeof(msgs)); for (i = 0; i < SIM_PACKETS; ++i) { iovecs[i].iov_base = xmalloc(MAX_PACKET_SIZE); iovecs[i].iov_len = MAX_PACKET_SIZE; msgs[i].msg_hdr.msg_iov = &iovecs[i]; msgs[i].msg_hdr.msg_iovlen = 1; }
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, reporter_len); log_splunk("sampler=statsd event=worker_online syscall=recvmsg socket=%d", sock); for (;;) { int res = recvfrom(sock, buffer, sizeof(buffer) - 1, 0, (struct sockaddr *)&reporter, &reporter_len); if (res == EAGAIN || res == EINTR || res == 0) continue; /* store stats */ brubeck_atomic_inc(&server->stats.metrics); brubeck_atomic_inc(&statsd->sampler.inflow); if (res < 0) { brubeck_server_mark_dropped(server); log_splunk_errno("sampler=statsd event=failed_read from=%s", inet_ntoa(reporter.sin_addr)); continue; }
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 != '\0') { /* Invalid metric, can't have a space */ if (*buffer == ' ') return -1; ++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 to off. */ LCDM1 = partstSEGMENTS_OFF; LCDM2 = partstSEGMENTS_OFF; LCDM3 = partstSEGMENTS_OFF; LCDM4 = partstSEGMENTS_OFF; LCDM5 = partstSEGMENTS_OFF; LCDM6 = partstSEGMENTS_OFF; LCDM7 = partstSEGMENTS_OFF; LCDM8 = partstSEGMENTS_OFF; LCDM9 = partstSEGMENTS_OFF; LCDM10 = partstSEGMENTS_OFF; LCDM11 = partstSEGMENTS_OFF; LCDM12 = partstSEGMENTS_OFF; LCDM13 = partstSEGMENTS_OFF; LCDM14 = partstSEGMENTS_OFF; LCDM15 = partstSEGMENTS_OFF; LCDM16 = partstSEGMENTS_OFF; LCDM17 = partstSEGMENTS_OFF; LCDM18 = partstSEGMENTS_OFF; LCDM19 = partstSEGMENTS_OFF; LCDM20 = partstSEGMENTS_OFF; /* Setup LCD control. */ LCDCTL = (LCDSG0_7|LCD4MUX|LCDON); }
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 '*'. */ *( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_ON; *( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_ON; }
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_OFF; *( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_OFF; }
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_MAX_HOST_NAME_LEN) return -2; query->name[len++] = '.'; }
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 (header->flags.qr != 0) goto error; if (ntohs(header->n_record[0]) != 1) goto error; len = parse_next_query(header + 1, p->len - sizeof(dns_header_t), &query); if (len < 0) goto error; if (!query_proc(query.name, &host_addr)) goto error; len += sizeof(dns_header_t); out = pbuf_alloc(PBUF_TRANSPORT, len + 16, PBUF_POOL); if (out == NULL) goto error; memcpy(out->payload, p->payload, len); header = (dns_header_t *)out->payload; header->flags.qr = 1; header->n_record[1] = htons(1); answer = (struct dns_answer *)((uint8_t *)out->payload + len); answer->name = htons(0xC00C); answer->type = htons(1); answer->Class = htons(1); answer->ttl = htonl(32); answer->len = htons(4); answer->addr = host_addr.addr; udp_sendto(upcb, out, addr, port); pbuf_free(out); error: pbuf_free(p); }
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; }