Ad Widget

Collapse

PATCH: simple checks (_perf)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hannibal20
    Junior Member
    • Jan 2007
    • 22

    #1

    PATCH: simple checks (_perf)

    I've been working with smtp_perf checks. This check always returns 0.0 in beta 1.3.2, but was ok in 1.1.5. This patch fixes what was lost in some code refactoring I suppose:

    Code:
    $ diff src/libs/zbxsysinfo/common/common.c src/libs/zbxsysinfo/common/common.c.orig 
    1620c1620
    <       if( strncmp(buf, expect, strlen(expect)) == 0 )
    ---
    >       if( strcmp(buf, expect) == 0 )
  • Alexei
    Founder, CEO
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2004
    • 5654

    #2
    Thanks for reporting this. Your patch has been integrated.
    Alexei Vladishev
    Creator of Zabbix, Product manager
    New York | Tokyo | Riga
    My Twitter

    Comment

    • medic
      Member
      • Feb 2007
      • 58

      #3
      very strange diff ...
      as "expect" is hardcoded, i dont see any problem here, although the use of strncmp() is more appreciated. These functions should be equal to each other in returnvalues ..

      could it already have been fixed by the patch you applied by the request of me (smtp service check broken), when the service appeared offline, because of the logic-bug ?

      Comment

      • Alexei
        Founder, CEO
        Zabbix Certified Trainer
        Zabbix Certified SpecialistZabbix Certified Professional
        • Sep 2004
        • 5654

        #4
        Originally posted by medic
        These functions should be equal to each other in returnvalues ..
        Think of strcmp("expect123","expect")!=strncmp("expect123", "expect",sizeof("expect"))
        Alexei Vladishev
        Creator of Zabbix, Product manager
        New York | Tokyo | Riga
        My Twitter

        Comment

        • medic
          Member
          • Feb 2007
          • 58

          #5
          Originally posted by Alexei
          Think of strcmp("expect123","expect")!=strncmp("expect123", "expect",sizeof("expect"))
          You really sure ?
          case 1 will try to find s2 in s1, but at least until one of the strings ends ...
          is s2 found in s1, and s2 ends, it returns 1.
          is s2 equal to s1 it returns 0
          is s2 not found in s1, it returns -1

          case 2 will try to find s2 in s1, but at least until one of the strings ends, or "sizeof("expect")" (n=chars+1 [cause of the nullbyte]) bytes are compared.
          is s2 found in s1, after s2 ends or n bytes are read, it returns 1.
          is s2 equal to s1 after s2 ends or n bytes it returns 0
          is s2 not found in s1 after s2 ends or n bytes are read, it returns -1

          at least this is way strcmp() strncmp() works on linux, and i'd guess *BSD it's the same ...
          I wrote a small program to find out if there's a bug in strcmp, but there isnt. the main reason for existing strncmp is to prevent BOFs, there is no (and should be no) diffrence in functionality ..


          #include <string.h>
          #include <stdio.h>

          int main () {

          printf("%d\n",strcmp("expect123","expect"));
          printf("%d\n",strncmp("expect123","expect",sizeof( "expect")));
          printf("%d\n",strncmp("expect123","expect",sizeof( "expect")-1)); // strip off nullbyte

          return(0);
          }


          medic@growsome ~ $ ./test2
          1 # found but not equal
          1 # found but not equal, because \0 != "1"
          0 # equal
          Last edited by medic; 25-03-2007, 18:05.

          Comment

          Working...