Changeset 448


Ignore:
Timestamp:
Mar 29, 2014, 7:59:38 AM (11 years ago)
Author:
katerina
Message:

Fic for ticket #350 (numeric hostnames).

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile.in

    r444 r448  
    18051805sh_audit.o: $(srcsrc)/sh_audit.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_extern.h $(srcinc)/sh_utils.h
    18061806sh_registry.o: $(srcsrc)/sh_registry.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_unix.h $(srcinc)/sh_modules.h $(srcinc)/sh_hash.h $(srcinc)/sh_tiger.h
    1807 sh_ipvx.o: $(srcsrc)/sh_ipvx.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_static.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_ipvx.h
     1807sh_ipvx.o: $(srcsrc)/sh_ipvx.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_static.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_ipvx.h $(srcinc)/CuTest.h
    18081808sh_restrict.o: $(srcsrc)/sh_restrict.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_mem.h $(srcinc)/sh_error_min.h $(srcinc)/sh_string.h $(srcinc)/sh_utils.h $(srcinc)/sh_restrict.h $(srcinc)/CuTest.h
    18091809sh_filetype.o: $(srcsrc)/sh_filetype.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_mem.h $(srcinc)/sh_error_min.h $(srcinc)/sh_utils.h
  • trunk/depend.dep

    r444 r448  
    8585sh_audit.o: $(srcsrc)/sh_audit.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_error.h $(srcinc)/sh_extern.h $(srcinc)/sh_utils.h
    8686sh_registry.o: $(srcsrc)/sh_registry.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_unix.h $(srcinc)/sh_modules.h $(srcinc)/sh_hash.h $(srcinc)/sh_tiger.h
    87 sh_ipvx.o: $(srcsrc)/sh_ipvx.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_static.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_ipvx.h
     87sh_ipvx.o: $(srcsrc)/sh_ipvx.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_static.h $(srcinc)/sh_pthread.h $(srcinc)/sh_utils.h $(srcinc)/sh_ipvx.h $(srcinc)/CuTest.h
    8888sh_restrict.o: $(srcsrc)/sh_restrict.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_mem.h $(srcinc)/sh_error_min.h $(srcinc)/sh_string.h $(srcinc)/sh_utils.h $(srcinc)/sh_restrict.h $(srcinc)/CuTest.h
    8989sh_filetype.o: $(srcsrc)/sh_filetype.c Makefile config_xor.h $(srcinc)/samhain.h $(srcinc)/sh_mem.h $(srcinc)/sh_error_min.h $(srcinc)/sh_utils.h
  • trunk/depend.sum

    r444 r448  
    1 3369499701
     13861086825
  • trunk/docs/Changelog

    r447 r448  
    113.1.1:
    22        * Disable inline asm on Cygwin (issue reported by Erik)
     3        * Fix sh_ipvx_is_ipv4 such that numeric hostnames are not
     4          incorrectly recognised as IP address (reported by A. Hofland)
    35
    463.1.0 (31-10-2013):
  • trunk/src/cutest_sh_tools.c

    r295 r448  
    114114  CuAssertTrue(tc, !sh_ipvx_is_numeric(input));
    115115  input  = strdup("127");
    116   CuAssertTrue(tc, sh_ipvx_is_numeric(input));
     116  CuAssertTrue(tc, !sh_ipvx_is_numeric(input));
    117117}
    118118
  • trunk/src/sh_ipvx.c

    r422 r448  
    4141{
    4242  int j;
     43  int count = 0;
    4344  int len = sl_strlen(addr);
     45  unsigned int a, b, c, d;
    4446 
    45   for (j = 0; j < len; ++j)
     47  if (len > 15) /* 3*4 + 3 dots */
     48    return (1 == 0);
     49
     50  for (j = 0; j < len; ++j) {
    4651    if ( (addr[j] < '0' || addr[j] > '9') && addr[j] != '.')
    4752      return (1 == 0);
     53    if (addr[j] == '.') ++count;
     54  }
     55
     56  if (count != 3)
     57    return (1 == 0);
     58
     59  if (sscanf(addr, "%3u.%3u.%3u.%3u", &a, &b, &c, &d) != 4)
     60    return( 1 == 0 );
     61
     62  if ((a|b|c|d) > 255)
     63    return( 1 == 0 );
     64
    4865  return (1 == 1);
    4966}
     
    538555  return 0;
    539556}
     557
     558#ifdef SH_CUTEST
     559#include <stdlib.h>
     560#include "CuTest.h"
     561
     562void Test_ipvx (CuTest *tc) {
     563
     564  int result;
     565
     566  result = sh_ipvx_is_ipv4("123456789");
     567  CuAssertTrue(tc, result == FALSE);
     568
     569  result = sh_ipvx_is_ipv4("123456789123...");
     570  CuAssertTrue(tc, result == FALSE);
     571
     572  result = sh_ipvx_is_ipv4("123.456.789.123");
     573  CuAssertTrue(tc, result == FALSE);
     574
     575  result = sh_ipvx_is_ipv4("123.156.189.254");
     576  CuAssertTrue(tc, result == TRUE);
     577
     578  result = sh_ipvx_is_ipv4("255.255.255.255");
     579  CuAssertTrue(tc, result == TRUE);
     580
     581  result = sh_ipvx_is_ipv4("0.0.0.0");
     582  CuAssertTrue(tc, result == TRUE);
     583
     584  result = sh_ipvx_is_ipv4("0022.156.189.254");
     585  CuAssertTrue(tc, result == FALSE);
     586
     587  result = sh_ipvx_is_ipv4("999999999.1.1.2");
     588  CuAssertTrue(tc, result == FALSE);
     589
     590}
     591#endif
     592
Note: See TracChangeset for help on using the changeset viewer.