Text  |   XML   |   Visible Warnings:

pvm3.4.6 : pvm3.4.6 analysis 2 : Buffer Overrun  at trcutil.c:602

Categories: LANG.MEM.BO CWE:120 CWE:121 CWE:122 CWE:126
Warning ID: 466.29229
Procedure: trc_add_to_trie
Trace: view
Modified: Thu Nov 26 11:36:21 2009   show details
 
Priority: None
State: None
Finding: None
Owner: None
  edit properties

Legend [ X ]
Warning Location
Contributes
Parse Error
Other Warning
Two or More Loop Iterations
On Execution Path
Comment
Macro
Preprocessor
Include
Keyword
Preprocessed Away

Source  |  Language: C Hide Legend     
ProblemLineSource
   /kat0/fletcher/SATE/2010/pvm3/tracer/trcfile.c
   Enter trc_read_trace_event
 2421 trc_read_trace_event( ID, eof ) 
 2422 TRC_ID ID;
 2423 int *eof;
 2424 {
 2425         TRC_TEVDESC TD;
 2426  
 2427         char tmp[4096];
 2428         char c;
 2429  
 2430         int entry_exit;
 2431         int dummy;
 2432         int index;
 2433         int code;
 2434         int flag;
 2435         int eid;
 2436         int ee;
 2437         int i;
 2438  
 2439         *eof = TRC_FALSE;
 2440  
 2441         if ( ID->trace_in == NULL )
 2442                 return( TRC_FALSE );
 2443  
 2444         while ( TRC_TRUE )
 2445         {
 2446                 c = getc( ID->trace_in );
 2447  
 2448                 if ( c != (char) EOF )
 2449                 {
 2450                         switch ( c ) 
 2451                         {
 2452                                 /* Record Descriptor Packet */ 
 2453  
 2454                                 case '#': 
 2455                                 {
 2456                                         /* Get event ID */ 
 2457  
 2458                                         flag = fscanf( ID->trace_in, "%d", &code );
 2459  
 2460                                         if ( flag != 1 )
 2461                                         {
 2462                                                 printf( "Error Reading Event ID\n" );
 2463  
 2464                                                 return( TRC_FALSE );
 2465                                         }
 2466  
 2467                                         /* Get event name */ 
 2468  
 2469                                         if ( !trc_find_event_str( ID, "\"" ) )
 2470                                                 return( TRC_FALSE );
 2471  
$input_630780 > 40962472                                         i = 0;
 2473  
 2474                                         while ( (c = getc( ID->trace_in )) != (char) EOF 
 2475                                                 && c != '"' && c != '(' )
 2476                                         {
 2477                                                 tmp[i++] = c;   /* Buffer Overrun (ID: 471.29235) */
 2478                                         }
 2479  
 2480                                         TRC_CKEOF( c, "EOF Reading Event Descriptor Name\n",
 2481                                                 return( TRC_FALSE ) );
 2482  
i > 40962483                                         tmp[i] = '\0';   /* Buffer Overrun (ID: 472.29236) */
 2484  
 2485                                         /* PVM 3.4 Trace */ 
 2486  
 2487                                         if ( c == '(' )
 2488                                         {
 2489                                                 /* Decode event ID */ 
 2490  
 2491                                                 index = ( code / 1000 ) - 1;
 2492  
 2493                                                 eid = ( code - ((index + 1) * 1000) ) / 2;
 2494  
 2495                                                 ee = code - ((index + 1) * 1000) - (2 * eid);
 2496  
 2497                                                 /* Read in entry/exit or index value */ 
 2498  
 2499                                                 flag = fscanf( ID->trace_in, "%d", &dummy );
 2500  
 2501                                                 if ( flag != 1 )
 2502                                                 {
 2503                                                         printf( "Error Reading Event Index\n" );
 2504  
 2505                                                         return( TRC_FALSE );
 2506                                                 }
 2507  
 2508                                                 /* Read in next char for parsing context */ 
 2509  
 2510                                                 c = getc( ID->trace_in );
 2511  
 2512                                                 TRC_CKEOF( c, "EOF Reading Event Descriptor\n",
 2513                                                         return( TRC_FALSE ) );
 2514  
 2515                                                 if ( c == '.' )
 2516                                                 {
 2517                                                         if ( ee != dummy )
 2518                                                         {
 2519                                                                 printf( "Warning:  " );
 2520                                                                 printf( "Entry/Exit Mismatch  " );
 2521                                                                 printf( "%d != %d\n", ee, dummy );
 2522                                                         }
 2523  
 2524                                                         entry_exit = TRC_IGNORE_TEV;
 2525  
 2526                                                         if ( dummy == 0 )
 2527                                                                 entry_exit = TRC_ENTRY_TEV;
 2528  
 2529                                                         else if ( dummy == 1 )
 2530                                                                 entry_exit = TRC_EXIT_TEV;
 2531  
 2532                                                         flag = fscanf( ID->trace_in, "%d", &dummy );
 2533  
 2534                                                         if ( flag != 1 )
 2535                                                         {
 2536                                                                 printf( "Error Reading Event Index\n" );
 2537  
 2538                                                                 return( TRC_FALSE );
 2539                                                         }
 2540  
 2541                                                         if ( index != dummy )
 2542                                                         {
 2543                                                                 printf( "Warning:  " );
 2544                                                                 printf( "Descriptor Index Mismatch  " );
 2545                                                                 printf( "%d != %d\n", index, dummy );
 2546  
 2547                                                                 index = dummy;
 2548                                                         }
 2549  
 2550                                                         if ( !trc_find_event_str( ID, ")" ) )
 2551                                                                 return( TRC_FALSE );
 2552                                                 }
 2553  
 2554                                                 else 
 2555                                                 {
 2556                                                         entry_exit = TRC_IGNORE_TEV;
 2557  
 2558                                                         if ( ee == 1 )
 2559                                                         {
 2560                                                                 printf( "Warning:  " );
 2561                                                                 printf( "Entry/Exit Mismatch  " );
 2562                                                                 printf( "%d != %d\n", ee, entry_exit );
 2563                                                         }
 2564  
 2565                                                         if ( index != dummy )
 2566                                                         {
 2567                                                                 printf( "Warning:  " );
 2568                                                                 printf( "Descriptor Index Mismatch  " );
 2569                                                                 printf( "%d != %d\n", index, dummy );
 2570  
 2571                                                                 index = dummy;
 2572                                                         }
 2573                                                 }
 2574  
strlen(&tmp[0]) > 40962575                                                 if ( !trc_find_event_str( ID, "\"" ) )
 2576                                                         return( TRC_FALSE );
 2577  
strlen($param_3) > bytes_after($param_3)2578                                                 if ( !(TD = trc_read_descriptor( 
strlen(&tmp[0]) > 40962579                                                         ID, eid, tmp, entry_exit, index )) )
     Enter trc_read_trace_event / trc_read_descriptor
 2766   trc_read_descriptor( ID, eid, name, entry_exit, index ) 
 2767   TRC_ID ID;
 2768   int eid;
 2769   char *name;
 2770   int entry_exit;
 2771   int index;
 2772   {
 2773           TRC_DATADESC DD;
 2774    
 2775           TRC_TEVDESC TD;
 2776           TRC_TEVDESC tdptr;
     ...
 2782           char last;
 2783           char c;
 2784    
 2785           long tmp;
 2786    
 2787           int done;
 2788           int i;
 2789    
 2790           /* Find first bracket */ 
 2791    
 2792           if ( !trc_find_event_str( ID, "{" ) )
 2793                   return( (TRC_TEVDESC) NULL );
 2794    
 2795           /* matching } */ 
 2796    
 2797           /* Create Descriptor Structure */ 
 2798    
 2799           TD = trc_create_tevdesc();   /* Leak (ID: 458.29219) */
 2800    
 2801           TD->refcount = 1;
 2802    
 2803           TD->name = trc_copy_str( name );   /* Leak (ID: 459.29220) */
 2804    
 2805           TD->eid = eid;
 2806    
 2807           TD->entry_exit = entry_exit;
 2808    
 2809           TD->index = index;
 2810    
 2811           /* Read in Data Descriptor Statements */ 
 2812    
 2813           done = 0;
 2814    
 2815           do 
 2816           {
 2817                   /* matching { */ 
 2818    
 2819                   while ( (c = getc( ID->trace_in )) != (char) EOF 
 2820                           && c != '/' && c != '}' );
 2821    
 2822                   TRC_CKEOF( c, "EOF Reading Event Descriptor\n",
 2823                           return( (TRC_TEVDESC) NULL ) );
 2824    
 2825                   /* Another Descriptor Statement */ 
 2826    
 2827                   if ( c == '/' )
 2828                   {
 2829                           if ( TD->ddesc == NULL )
 2830                                   DD = TD->ddesc = trc_create_datadesc();   /* Leak (ID: 457.29218) */
 2831    
 2832                           else 
 2833                                   DD = DD->next = trc_create_datadesc();
 2834    
 2835                           /* Get Second '/' */ 
 2836    
 2837                           c = getc( ID->trace_in );
     ...
 3008                                   else 
 3009                                           DD->array = TEV_DATA_ARRAY;
 3010                           }
 3011    
 3012                           else 
 3013                                   DD->array = TEV_DATA_SCALAR;
 3014                   }
 3015    
 3016                   /* End of Descriptor */ 
 3017    
 3018                   else 
 3019                   {
 3020                           if ( !trc_find_event_end( ID ) )
 3021                                   return( (TRC_TEVDESC) NULL );
 3022    
 3023                           done++;
 3024                   }
 3025           }
 3026           while ( !done );
 3027    
 3028           tdptr = (TRC_TEVDESC) trc_lookup_trie( TRC_EVENT_TRIE, name );
 3029    
 3030           if ( tdptr == NULL )
strlen(name) > bytes_after(name)3031                   trc_add_to_trie( TRC_EVENT_TRIE, name, (void *) TD );
       /kat0/fletcher/SATE/2010/pvm3/tracer/trcutil.c
       Enter trc_read_trace_event / trc_read_descriptor / trc_add_to_trie
 521     trc_add_to_trie( T, str, value ) 
 522     TRC_TRIE T;
 523     char *str;
 524     void *value;
 525     {
 526             TRC_TRIE tptr;
 527      
 528             char *bump;
 529      
 530             int bumpindex;
 531             int marked;
 532             int index;
 533             int len;
 534             int i;
 535      
 536             if ( T == NULL )
 537             {
 538                     printf( "\nError in trc_add_to_trie(): Null Trie\n\n" );
 539      
 540                     return( TRC_FALSE );
 541             }
 542      
 543             if ( str == NULL || !strcmp( str, "" ) )
 544             {
 545                     printf( "\nError in trc_add_to_trie(): Empty String\n\n" );
 546      
 547                     return( TRC_FALSE );
 548             }
 549      
strlen(str) > bytes_after(str)550             len = strlen( str ) - 1;
 551      
 552             marked = 0;
 553      
 554             for ( i=0 ; i < len && !marked ; i++ )
 555             {
 556                     index = trc_trie_index( str[i] );
 557      
 558                     tptr = &(T[index]);
 559      
 560                     if ( tptr->next != NULL )
 561                             T = tptr->next;
 562      
 563                     else 
 564                     {
 565                             if ( !tptr->valid )
 566                             {
 567                                     tptr->valid = TRC_TRUE;
 568      
 569                                     tptr->str = trc_copy_str( str );
 570      
 571                                     tptr->value = value;
 572      
 573                                     marked++;
 574                             }
 575      
 576                             else 
 577                             {
 578                                     tptr->next = trc_create_triestack();
 579      
 580                                     T = tptr->next;
 581      
 582                                     bump = tptr->str;
 583      
 584                                     if ( strlen( bump ) > i + 1 )
 585                                     {
 586                                             bumpindex = trc_trie_index( bump[ i + 1 ] );
 587      
 588                                             T[bumpindex].valid = TRC_TRUE;
 589                                             T[bumpindex].str = bump;
 590                                             T[bumpindex].value = tptr->value;
 591      
 592                                             tptr->valid = TRC_FALSE;
 593                                             tptr->str = (char *) NULL;
 594                                             tptr->value = (void *) NULL;
 595                                     }
 596                             }
 597                     }
 598             }
 599      
 600             if ( !marked )
 601             {
len > bytes_after(str) - 1602                     index = trc_trie_index( str[len] );     /* Buffer Overrun */  /* Buffer Underrun (ID: 22174.29230) */
       Exit trc_read_trace_event / trc_read_descriptor / trc_add_to_trie
     Exit trc_read_trace_event / trc_read_descriptor
 2580                                                 {
 2581                                                         return( TRC_FALSE );
 2582                                                 }
 2583  
 2584                                                 if ( ID->handle_descriptor )
 2585                                                         (ID->handle_descriptor)( ID, TD );
 2586                                         }
 2587  
 2588                                         /* PVM 3.3 Trace - Ignore Descriptor */ 
 2589  
 2590                                         else 
 2591                                         {
 2592                                                 eid = code;
 2593  
 2594                                                 if ( tmp[ i - 1 ] == '0' )   /* Buffer Underrun (ID: 470.29234) */  /* Buffer Overrun (ID: 469.29233) */
 2595                                                         entry_exit = TRC_ENTRY_TEV;
 2596  
 2597                                                 else if ( tmp[ i - 1 ] == '1' )   /* Buffer Overrun (ID: 467.29231) */  /* Buffer Underrun (ID: 468.29232) */
 2598                                                         entry_exit = TRC_EXIT_TEV;
 2599  
 2600                                                 else 
 2601                                                         entry_exit = TRC_IGNORE_TEV;
 2602  
 2603                                                 if ( !(TD = trc_read_descriptor( 
 2604                                                         ID, eid, tmp, entry_exit, -1 )) )
 2605                                                 {
 2606                                                         return( TRC_FALSE );
 2607                                                 }
 2608  
 2609                                                 if ( ID->handle_old_descriptor )
 2610                                                         (ID->handle_old_descriptor)( ID, TD );
 2611                                         }
 2612  
 2613                                         break;
 2614                                 }
 2615  
 2616                                 /* Record Data Packet */ 
 2617  
 2618                                 case '"': 
 2619                                 {
 2620                                         i = 0;
 2621  
 2622                                         while ( (c = getc( ID->trace_in )) != (char) EOF 
 2623                                                 && c != '"' && c != '(' )
   ...
 2695                                         {
 2696                                                 return( 
 2697                                                         trc_process_old_trace_event( ID, tmp ) );
 2698                                         }
 2699  
 2700                                         /* break; unreachable */ 
 2701                                 }
 2702  
 2703                                 /* Command Packet */ 
 2704  
 2705                                 case '%': 
 2706                                 {
 2707                                         tmp[0] = '%';
 2708  
 2709                                         if ( !trc_find_event_end_ret( ID, tmp + 1, 4095 ) )
 2710                                                 return( TRC_FALSE );
 2711  
 2712                                         if ( ID->handle_command )
 2713                                                 (ID->handle_command)( ID, tmp );
 2714  
 2715                                         break;
 2716                                 }
 2717  
 2718                                 /* Stream Attribute Packet */ 
 2719  
 2720                                 case '/': 
 2721                                 {
 2722                                         c = getc( ID->trace_in );
 2723  
 2724                                         TRC_CKEOF( c, "EOF Reading Trace Comment\n",
 2725                                                 return( TRC_FALSE ) );
 2726  
 2727                                         if ( c != '*' )
 2728                                         {
 2729                                                 printf( "\nError Reading Trace File\n" );
 2730                                                 printf( "\t- '*' expected (/* */)\n\n" );
 2731                                         }
 2732  
 2733                                         strcpy( tmp, "/*" );
 2734  
 2735                                         if ( !trc_find_event_end_ret( ID, tmp + 2, 4094 ) )
 2736                                                 return( TRC_FALSE );
 2737  
 2738                                         if ( ID->handle_comment )
 2739                                                 (ID->handle_comment)( ID, tmp );
 2740  
 2741                                         break;
 2742                                 }
 2743  
 2744                                 /* White Space */ 
 2745  
 2746                                 case ' ': 
 2747                                 case '\t': 
 2748                                 case '\n': 
 2749                                 {
 2750                                         break;
Preconditions
TRC_EVENT_TRIE != 0
((char*)&$unknown_12090437)[12] != 0
$input_12 = 1
$input_630780 >= 3
$input_646204 = 35
$input_646220 = 1
$input_646228 = 40
$input_646244 = 46
$input_646260 = 1
$input_646268 = 125
Postconditions
ID' = ID
T' = ((char*)&$unknown_12090437)[12]
TD' = &$heap_435934
$unknown_12090426' is allocated by fopen
bytes_before(&$unknown_12090426)' = 0
c' = $input_646268
c' = $input_646244
code' = $input_646212
done' = 1
dummy' = $input_646252
ee' != 1
eid' = eid'
entry_exit' = 1
entry_exit' = 1
flag' = $input_646260
$heap_435934' = &$heap_435935
bytes_after(&$heap_435934)' = 36
$heap_435934' is allocated by malloc
$heap_435934' is allocated
bytes_before(&$heap_435934)' = 0
((char*)&$heap_435934)[16]' = -1
((char*)&$heap_435934)[20]' = -1
((char*)&$heap_435934)[24]' = 0
((char*)&$heap_435934)[28]' = 1
((char*)&$heap_435934)[32]' = 0
((char*)&$heap_435934)[8]' = 1
((char*)&$heap_435934)[12]' = $input_646252
bytes_after(&$heap_435935)' = $input_630780 + 1
$heap_435935' is allocated by malloc
$heap_435935' is allocated
bytes_before(&$heap_435935)' = 0
strlen(&$heap_435935)' = $input_630780
i' = $input_630780
i' = $input_630780 - 1
index' = $input_646252
index' = $input_646252
len' = $input_630780 - 1
marked' = 0
name' = &tmp[0]
str' = &tmp[0]
tdptr' = 0
tmp[0]' = $heap_435935'
strlen(&tmp[0])' = $input_630780
tptr' = &$unknown_12090437
value' = &$heap_435934




Change Warning 466.29229 : Buffer Overrun

Priority:
State:
Finding:
Owner:
Note: