Text   |  XML   |  ReML   |   Visible Warnings:

File System Race Condition  at iax2_analysis.c:2251

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

copy_file

(/home/sate/Testcases/c/cve/wireshark-1.2.0/gtk/iax2_analysis.c)expand/collapse
Show more  
 2227  static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t *user_data)
 2228  {
 2229          int to_fd, forw_fd, rev_fd, fread = 0, rread = 0, fwritten, rwritten;
 2230          gchar f_pd[1] = {0};
 2231          gchar r_pd[1] = {0};
 2232          gint16 sample;
 2233          gchar pd[4];
 2234          guint32 f_write_silence = 0;
 2235          guint32 r_write_silence = 0;
 2236          progdlg_t *progbar;
 2237          guint32 progbar_count, progbar_quantum, progbar_nextstep = 0, count = 0;
 2238          gboolean stop_flag = FALSE;
 2239          size_t nchars;
 2240   
 2241          forw_fd = ws_open(user_data->f_tempname, O_RDONLY | O_BINARY, 0000 /* no creation so don't matter */);
 2242          if (forw_fd < 0)
 2243                  return FALSE;
 2244          rev_fd = ws_open(user_data->r_tempname, O_RDONLY | O_BINARY, 0000 /* no creation so don't matter */);
 2245          if (rev_fd < 0) {
 2246                  ws_close(forw_fd);
 2247                  return FALSE;
 2248          }
 2249   
 2250          /* open file for saving */
 2251          to_fd = ws_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
Show more  
Show more  




Change Warning 4389.30415 : File System Race Condition

Priority:
State:
Finding:
Owner:
Note: