Text   |  XML   |  ReML   |   Visible Warnings:

Unreachable Control Flow  at filters.c:377

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

read_filter_list

(/home/sate/Testcases/c/cve/wireshark-1.2.0/filters.c)expand/collapse
Show more  
 115  read_filter_list(filter_list_type_t list_type, char **pref_path_return,
 116      int *errno_return)
 117  {
 118    const char *ff_name;
 119    char       *ff_path;
 120    FILE       *ff;
 121    GList      **flpp;
 122    int         c;
 123    char       *filt_name, *filt_expr;
 124    int         filt_name_len, filt_expr_len;
 125    int         filt_name_index, filt_expr_index;
 126    int         line = 1;
 127   
 128    *pref_path_return = NULL;     /* assume no error */
 129   
 130    switch (list_type) {
 131   
 132    case CFILTER_LIST:
 133      ff_name = CFILTER_FILE_NAME;
 134      flpp = &capture_filters;
 135      break;
 136   
 137    case DFILTER_LIST:
 138      ff_name = DFILTER_FILE_NAME;
 139      flpp = &display_filters;
 140      break;
 141   
 142    default:
 143      g_assert_not_reached();
 144      return;
 145    }
 146   
 147    /* try to open personal "cfilters"/"dfilters" file */
 148    ff_path = get_persconffile_path(ff_name, TRUE, FALSE);
 149    if ((ff = ws_fopen(ff_path, "r")) == NULL) {
 150      /*
 151       * Did that fail because the file didn't exist?
 152       */
 153      if (errno != ENOENT) {
 154        /*
 155         * No.  Just give up.
 156         */
 157        *pref_path_return = ff_path;
 158        *errno_return = errno;
 159        return;
 160      }
 161   
 162      /*
 163       * Yes.  See if there's an "old style" personal "filters" file; if so, read it.
 164       * This means that a user will start out with their capture and
 165       * display filter lists being identical; each list may contain
 166       * filters that don't belong in that list.  The user can edit 
 167       * the filter lists, and delete the ones that don't belong in
 168       * a particular list.
 169       */
 170      g_free(ff_path);
 171      ff_path = get_persconffile_path(FILTER_FILE_NAME, FALSE, FALSE);
 172      if ((ff = ws_fopen(ff_path, "r")) == NULL) {
 173        /*
 174         * Did that fail because the file didn't exist?
 175         */
 176          if (errno != ENOENT) {
 177          /*
 178           * No.  Just give up.
 179           */
 180            *pref_path_return = ff_path;
 181            *errno_return = errno;
 182            return;
 183          }
 184   
 185        /*
 186         * Try to open the global "cfilters/dfilters" file */
 187        g_free(ff_path);
 188        ff_path = get_datafile_path(ff_name);
 189        if ((ff = ws_fopen(ff_path, "r")) == NULL) {
 190   
 191          /*
 192           * Well, that didn't work, either.  Just give up.
 193           * Return an error if the file existed but we couldn't open it.
 194           */
 195          if (errno != ENOENT) {
 196            *pref_path_return = ff_path;
 197            *errno_return = errno;
 198          } else {
 199            g_free(ff_path);
 200          }
 201          return;
 202        }
 203      }
 204    }
 205   
 206    /* If we already have a list of filters, discard it. */
 207    /* this should never happen - this function is called only once for each list! */
 208    while(*flpp) {
 209      *flpp = remove_filter_entry(*flpp, g_list_first(*flpp));
 210    }
 211   
 212    /* Allocate the filter name buffer. */
 213    filt_name_len = INIT_BUF_SIZE;
 214    filt_name = g_malloc(filt_name_len + 1);
 215    filt_expr_len = INIT_BUF_SIZE;
 216    filt_expr = g_malloc(filt_expr_len + 1);
 217   
 218    for (line = 1; ; line++) {
 219      /* Lines in a filter file are of the form 
 220   
 221          "name" expression 
 222   
 223         where "name" is a name, in quotes - backslashes in the name
 224         escape the next character, so quotes and backslashes can appear
 225         in the name - and "expression" is a filter expression, not in
 226         quotes, running to the end of the line. */
 227   
 228      /* Skip over leading white space, if any. */
 229      while ((c = getc(ff)) != EOF && isspace(c)) {
 230        if (c == '\n') {
 231          /* Blank line. */
 232          continue;
 233        }
 234      }
 235   
 236      if (c == EOF)
 237        break;    /* Nothing more to read */
 238   
 239      /* "c" is the first non-white-space character.
 240         If it's not a quote, it's an error. */
 241      if (c != '"') {
 242        g_warning("'%s' line %d doesn't have a quoted filter name.", ff_path,
 243                  line);
 244        while (c != '\n')
 245          c = getc(ff);   /* skip to the end of the line */
 246        continue;
 247      }
 248   
 249      /* Get the name of the filter. */
 250      filt_name_index = 0;
 251      for (;;) {
 252        c = getc(ff);
 253        if (c == EOF || c == '\n')
 254          break;  /* End of line - or end of file */
 255        if (c == '"') {
 256          /* Closing quote. */
 257          if (filt_name_index >= filt_name_len) {
 258            /* Filter name buffer isn't long enough; double its length. */
 259            filt_name_len *= 2;
 260            filt_name = g_realloc(filt_name, filt_name_len + 1);
 261          }
 262          filt_name[filt_name_index] = '\0';
 263          break;
 264        }
 265        if (c == '\\') {
 266          /* Next character is escaped */
 267          c = getc(ff);
 268          if (c == EOF || c == '\n')
 269            break;        /* End of line - or end of file */
 270        }
 271        /* Add this character to the filter name string. */
 272        if (filt_name_index >= filt_name_len) {
 273          /* Filter name buffer isn't long enough; double its length. */
 274          filt_name_len *= 2;
 275          filt_name = g_realloc(filt_name, filt_name_len + 1);
 276        }
 277        filt_name[filt_name_index] = c;
 278        filt_name_index++;
 279      }
 280   
 281      if (c == EOF) {
 282        if (!ferror(ff)) {
 283          /* EOF, not error; no newline seen before EOF */
 284          g_warning("'%s' line %d doesn't have a newline.", ff_path,
 285                    line);
 286        }
 287        break;    /* nothing more to read */
 288      }
 289   
 290      if (c != '"') {
 291        /* No newline seen before end-of-line */
 292        g_warning("'%s' line %d doesn't have a closing quote.", ff_path,
 293                  line);
 294        continue;
 295      }
 296   
 297      /* Skip over separating white space, if any. */
 298      while ((c = getc(ff)) != EOF && isspace(c)) {
 299        if (c == '\n')
 300          break;
 301      }
 302   
 303      if (c == EOF) {
 304        if (!ferror(ff)) {
 305          /* EOF, not error; no newline seen before EOF */
 306          g_warning("'%s' line %d doesn't have a newline.", ff_path,
 307                    line);
 308        }
 309        break;    /* nothing more to read */
 310      }
 311   
 312      if (c == '\n') {
 313        /* No filter expression */
 314        g_warning("'%s' line %d doesn't have a filter expression.", ff_path,
 315                  line);
 316        continue;
 317      }
 318   
 319      /* "c" is the first non-white-space character; it's the first
 320         character of the filter expression. */
 321      filt_expr_index = 0;
 322      for (;;) {
 323        /* Add this character to the filter expression string. */
 324        if (filt_expr_index >= filt_expr_len) {
 325          /* Filter expressioin buffer isn't long enough; double its length. */
 326          filt_expr_len *= 2;
 327          filt_expr = g_realloc(filt_expr, filt_expr_len + 1);
 328        }
 329        filt_expr[filt_expr_index] = c;
 330        filt_expr_index++;
 331   
 332        /* Get the next character. */
 333        c = getc(ff);
 334        if (c == EOF || c == '\n')
 335          break;
 336      }
 337   
 338      if (c == EOF) {
 339        if (!ferror(ff)) {
 340          /* EOF, not error; no newline seen before EOF */
 341          g_warning("'%s' line %d doesn't have a newline.", ff_path,
 342                    line);
 343        }
 344        break;    /* nothing more to read */
 345      }
 346   
 347      /* We saw the ending newline; terminate the filter expression string */
 348      if (filt_expr_index >= filt_expr_len) {
 349        /* Filter expressioin buffer isn't long enough; double its length. */
 350        filt_expr_len *= 2;
 351        filt_expr = g_realloc(filt_expr, filt_expr_len + 1);
 352      }
 353      filt_expr[filt_expr_index] = '\0';
 354   
 355      /* Add the new filter to the list of filters */
 356      *flpp = add_filter_entry(*flpp, filt_name, filt_expr);
 357    }
 358    if (ferror(ff)) {
 359      *pref_path_return = ff_path;
 360      *errno_return = errno;
 361    } else 
 362      g_free(ff_path);
 363    fclose(ff);
 364    g_free(filt_name);
 365    g_free(filt_expr);
 366   
 367    /* init the corresponding edited list */
 368    switch (list_type) {
 369    case CFILTER_LIST:
 370      copy_filter_list(CFILTER_EDITED_LIST, CFILTER_LIST);
 371      break;
 372    case DFILTER_LIST:
 373      copy_filter_list(DFILTER_EDITED_LIST, DFILTER_LIST);
 374      break;
 375    default:
 376      g_assert_not_reached();
 377      return;
 378    }
 379  }
Show more  




Change Warning 4135.30348 : Unreachable Control Flow

Because they are very similar, this warning shares annotations with warning 4135.30349.

Priority:
State:
Finding:
Owner:
Note: