cvs commit: src/sbin/ipfw ipfw2.c

Brooks Davis brooks at FreeBSD.org
Fri Jan 14 17:46:42 PST 2005


brooks      2005-01-15 01:46:41 UTC

  FreeBSD src repository

  Modified files:
    sbin/ipfw            ipfw2.c 
  Log:
  Deprecate unmaintainable uses of strncmp to implement abbreviations.
  This commit replaces those with two new functions that simplify the code
  and produce warnings that the syntax is deprecated.  A small number of
  sensible abbreviations may be explicitly added based on user feedback.
  
  There were previously three types of strncmp use in ipfw:
   - Most commonly, strncmp(av, "string", sizeof(av)) was used to allow av
     to match string or any shortened form of it.  I have replaced this
     with a new function _substrcmp(av, "string") which returns 0 if av
     is a substring of "string", but emits a warning if av is not exactly
     "string".
  
   - The next type was two instances of strncmp(av, "by", 2) which allowed
     the abbreviation of bytes to "by", "byt", etc.  Unfortunately, it
     also supported "bykHUygh&*g&*7*ui".  I added a second new function
     _substrcmp2(av, "by", "bytes") which acts like the strncmp did, but
     complains if the user doesn't spell out the word "bytes".
  
   - There is also one correct use of strncmp to match "table(" which might
     have another token after it without a space.
  
  Since I changed all the lines anyway, I also fixed the treatment of
  strncmp's return as a boolean in many cases.  I also modified a few
  strcmp cases as well to be fully consistent.
  
  Revision  Changes    Path
  1.67      +112 -60   src/sbin/ipfw/ipfw2.c


More information about the cvs-src mailing list