Text   |  XML   |  ReML   |   Visible Warnings:

File System Race Condition  at rtp_analysis.c:2272

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

save_voice_as_ok_cb

(/home/sate/Testcases/c/cve/wireshark-1.2.0/gtk/rtp_analysis.c)expand/collapse
Show more  
 2539  static gboolean save_voice_as_ok_cb(GtkWidget *w _U_, gpointer fc)
 2540  {
 2541          gchar *g_dest;
 2542          /*GtkWidget *wav, *sw;*/
 2543          GtkWidget *au, *raw;
 2544          GtkWidget *rev, *forw, *both;
 2545          user_data_t *user_data;
 2546          gint channels, format;
 2547   
 2548          g_dest = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fc));
 2549   
 2550          /* Perhaps the user specified a directory instead of a file.
 2551           * Check whether they did.
 2552           */
 2553[+]         if (test_for_directory(g_dest) == EISDIR) {
 2554                  /* It's a directory - set the file selection box to display it. */
 2555                  set_last_open_dir(g_dest);
 2556                  g_free(g_dest);
 2557                  file_selection_set_current_folder(fc, get_last_open_dir());
 2558                  gtk_file_chooser_set_current_name(fc, "");
 2559                  return FALSE; /* run the dialog again */
 2560          }
 2561   
 2562  #if 0 
 2563          wav  = (GtkWidget *)g_object_get_data(G_OBJECT(fc), "wav_rb");
 2564          sw   = (GtkWidget *)g_object_get_data(G_OBJECT(fc), "sw_rb");
 2565  #endif
 2566          au   = (GtkWidget *)g_object_get_data(G_OBJECT(fc), "au_rb");
 2567          raw  = (GtkWidget *)g_object_get_data(G_OBJECT(fc), "raw_rb");
 2568          rev  = (GtkWidget *)g_object_get_data(G_OBJECT(fc), "reversed_rb");
 2569          forw = (GtkWidget *)g_object_get_data(G_OBJECT(fc), "forward_rb");
 2570          both = (GtkWidget *)g_object_get_data(G_OBJECT(fc), "both_rb");
 2571          user_data = (user_data_t *)g_object_get_data(G_OBJECT(fc), "user_data");
 2572   
 2573          /* XXX user clicks the ok button, but we know we can't save the voice info because f.e.
 2574          * we don't support that codec. So we pop up a warning. Maybe it would be better to
 2575          * disable the ok button or disable the buttons for direction if only one is not ok. The 
 2576          * problem is if we open the save voice dialog and then click the refresh button and maybe 
 2577          * the state changes, so we can't save anymore. In this case we should be able to update 
 2578          * the buttons. For now it is easier if we put the warning when the ok button is pressed.
 2579          */
 2580   
 2581          /* we can not save in both directions */
 2582          if ((user_data->forward.saveinfo.saved == FALSE) && (user_data->reversed.saveinfo.saved == FALSE) && (GTK_TOGGLE_BUTTON (both)->active)) {
 2583                  /* there are many combinations here, we just exit when first matches */
 2584                  if ((user_data->forward.saveinfo.error_type == TAP_RTP_WRONG_CODEC) ||
 2585                          (user_data->reversed.saveinfo.error_type == TAP_RTP_WRONG_CODEC))
 2586                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2587                          "Can't save in a file: Unsupported codec!");
 2588                  else if ((user_data->forward.saveinfo.error_type == TAP_RTP_WRONG_LENGTH) ||
 2589                          (user_data->reversed.saveinfo.error_type == TAP_RTP_WRONG_LENGTH))
 2590                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2591                          "Can't save in a file: Wrong length of captured packets!");
 2592                  else if ((user_data->forward.saveinfo.error_type == TAP_RTP_PADDING_ERROR) ||
 2593                          (user_data->reversed.saveinfo.error_type == TAP_RTP_PADDING_ERROR))
 2594                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2595                          "Can't save in a file: RTP data with padding!");
 2596                  else if ((user_data->forward.saveinfo.error_type == TAP_RTP_SHORT_FRAME) ||
 2597                          (user_data->reversed.saveinfo.error_type == TAP_RTP_SHORT_FRAME))
 2598                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2599                          "Can't save in a file: Not all data in all packets was captured!");
 2600                  else 
 2601                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2602                          "Can't save in a file: File I/O problem!");
 2603                  g_free(g_dest);
 2604                  return TRUE; /* we're done */
 2605          }
 2606          /* we can not save forward direction */
 2607          else if ((user_data->forward.saveinfo.saved == FALSE) && ((GTK_TOGGLE_BUTTON (forw)->active) ||
 2608                  (GTK_TOGGLE_BUTTON (both)->active))) {
 2609                  if (user_data->forward.saveinfo.error_type == TAP_RTP_WRONG_CODEC)
 2610                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2611                          "Can't save forward direction in a file: Unsupported codec!");
 2612                  else if (user_data->forward.saveinfo.error_type == TAP_RTP_WRONG_LENGTH)
 2613                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2614                          "Can't save forward direction in a file: Wrong length of captured packets!");
 2615                  else if (user_data->forward.saveinfo.error_type == TAP_RTP_PADDING_ERROR)
 2616                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2617                          "Can't save forward direction in a file: RTP data with padding!");
 2618                  else if (user_data->forward.saveinfo.error_type == TAP_RTP_SHORT_FRAME)
 2619                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2620                          "Can't save forward direction in a file: Not all data in all packets was captured!");
 2621                  else 
 2622                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2623                          "Can't save forward direction in a file: File I/O problem!");
 2624                  g_free(g_dest);
 2625                  return TRUE; /* we're done */
 2626          }
 2627          /* we can not save reversed direction */
 2628          else if ((user_data->reversed.saveinfo.saved == FALSE) && ((GTK_TOGGLE_BUTTON (rev)->active) ||
 2629                  (GTK_TOGGLE_BUTTON (both)->active))) {
 2630                  if (user_data->reversed.saveinfo.error_type == TAP_RTP_WRONG_CODEC)
 2631                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2632                          "Can't save reversed direction in a file: Unsupported codec!");
 2633                  else if (user_data->reversed.saveinfo.error_type == TAP_RTP_WRONG_LENGTH)
 2634                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2635                          "Can't save reversed direction in a file: Wrong length of captured packets!");
 2636                  else if (user_data->reversed.saveinfo.error_type == TAP_RTP_PADDING_ERROR)
 2637                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2638                          "Can't save reversed direction in a file: RTP data with padding!");
 2639                  else if (user_data->reversed.saveinfo.error_type == TAP_RTP_SHORT_FRAME)
 2640                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2641                          "Can't save reversed direction in a file: Not all data in all packets was captured!");
 2642                  else if (user_data->reversed.saveinfo.error_type == TAP_RTP_NO_DATA)
 2643                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2644                          "Can't save reversed direction in a file: No RTP data!");
 2645                  else 
 2646                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2647                          "Can't save reversed direction in a file: File I/O problem!");
 2648                  g_free(g_dest);
 2649                  return TRUE; /* we're done */
 2650          }
 2651   
 2652  #if 0 
 2653          if (GTK_TOGGLE_BUTTON (wav)->active)
 2654                  format = SAVE_WAV_FORMAT;
 2655          else 
 2656  #endif
 2657          if (GTK_TOGGLE_BUTTON (au)->active)
 2658                  format = SAVE_AU_FORMAT;
 2659  #if 0 
 2660          else if (GTK_TOGGLE_BUTTON (sw)->active)
 2661                  format = SAVE_SW_FORMAT;
 2662  #endif
 2663          else if (GTK_TOGGLE_BUTTON (raw)->active)
 2664                  format = SAVE_RAW_FORMAT;
 2665          else 
 2666                  format = SAVE_NONE_FORMAT;
 2667   
 2668          if (GTK_TOGGLE_BUTTON (rev)->active)
 2669                  channels = SAVE_REVERSE_DIRECTION_MASK;
 2670          else if (GTK_TOGGLE_BUTTON (both)->active)
 2671                  channels = SAVE_BOTH_DIRECTION_MASK;
 2672          else 
 2673                  channels = SAVE_FORWARD_DIRECTION_MASK;
 2674   
 2675          /* direction/format validity*/
 2676          if (format == SAVE_AU_FORMAT)
 2677          {
 2678                  /* make sure streams are alaw/ulaw */
 2679                  if ((channels & SAVE_FORWARD_DIRECTION_MASK) && (user_data->forward.statinfo.pt != PT_PCMA) && (user_data->forward.statinfo.pt != PT_PCMU)){
 2680                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2681                                  "Can't save in a file: saving in au format supported only for alaw/ulaw streams");
 2682                          g_free(g_dest);
 2683                          return TRUE; /* we're done */
 2684                  }
 2685                  if ((channels & SAVE_REVERSE_DIRECTION_MASK) && (user_data->reversed.statinfo.pt != PT_PCMA) && (user_data->reversed.statinfo.pt != PT_PCMU)){
 2686                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2687                                  "Can't save in a file: saving in au format supported only for alaw/ulaw streams");
 2688                          g_free(g_dest);
 2689                          return TRUE; /* we're done */
 2690                  }
 2691                  /* make sure pt's don't differ */
 2692                  if ((channels == SAVE_BOTH_DIRECTION_MASK) && (user_data->forward.statinfo.pt != user_data->reversed.statinfo.pt)){
 2693                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2694                                  "Can't save in a file: Forward and reverse direction differ in type");
 2695                          g_free(g_dest);
 2696                          return TRUE; /* we're done */
 2697                  }
 2698          }
 2699          else if (format == SAVE_RAW_FORMAT)
 2700          {
 2701                  /* can't save raw in both directions */
 2702                  if (channels == SAVE_BOTH_DIRECTION_MASK){
 2703                          simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2704                                  "Can't save in a file: Unable to save raw data in both directions");
 2705                          g_free(g_dest);
 2706                          return TRUE; /* we're done */
 2707                  }
 2708          }
 2709          else 
 2710          {
 2711                  simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
 2712                          "Can't save in a file: Invalid save format");
 2713                  g_free(g_dest);
 2714                  return TRUE; /* we're done */
 2715          }
 2716   
 2717[+]         if(!copy_file(g_dest, channels, format, user_data)) {
expand/collapse

copy_file

(/home/sate/Testcases/c/cve/wireshark-1.2.0/gtk/rtp_analysis.c)expand/collapse
Show more  
 2248  static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t *user_data)
 2249  {
 2250          FILE *to_stream, *forw_stream, *rev_stream;
 2251          size_t fwritten, rwritten;
 2252          int f_rawvalue, r_rawvalue, rawvalue;
 2253          gint16 sample;
 2254          gchar pd[4];
 2255          guint32 f_write_silence = 0;
 2256          guint32 r_write_silence = 0;
 2257          progdlg_t *progbar;
 2258          guint32 progbar_count, progbar_quantum, progbar_nextstep = 0, count = 0;
 2259          gboolean stop_flag = FALSE;
 2260          size_t nchars;
 2261   
 2262          forw_stream = ws_fopen(user_data->f_tempname, "rb");
 2263          if (forw_stream == NULL)
 2264                  return FALSE;
 2265          rev_stream = ws_fopen(user_data->r_tempname, "rb");
 2266          if (rev_stream == NULL) {
 2267                  fclose(forw_stream);
 2268                  return FALSE;
 2269          }
 2270   
 2271          /* open file for saving */
 2272          to_stream = ws_fopen(dest, "wb");
Show more  
Show more  




Change Warning 4414.30416 : File System Race Condition

Priority:
State:
Finding:
Owner:
Note: