Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-7013

non-standard strndup is used in dbupgrade.c file, DBpatch_2010101 function

XMLWordPrintable

    • Icon: Incident report Incident report
    • Resolution: Fixed
    • Icon: Minor Minor
    • 2.2.0
    • 2.1.4
    • Server (S)
    • None
    • Solaris x86, Sun Studio 12

      The strndup function is used in src/libs/zbxdbupgrade/dbupgrade.c in DBpatch_2010101 function. It is GNU function, not standard, so can't compile server and link zabbix server with SunStudio CC and guess same for other compilers except gcc.

      I fix it by the following code. but couldn't be a good choice.

      #Fix strndup issue on dbuphgrade.c
      STRNDUP_FUNC="//#if defined(SOLARIS)||defined(_APPLE) || defined(WIN32) || defined(_FORTEC)
      #define min(a,b) (a>b?b:a)
      char *strndup( const char *s, size_t n )

      { size_t nAvail; char *p; if ( !s ) return 0; nAvail = min( strlen(s) + 1, n + 1 ); p = malloc( nAvail ); memcpy( p, s, nAvail ); p[nAvail - 1] = '\0'; /* printf( \"[PAH][%s][%d] nAvail=%d p=(%s)\n\", __FILE__, __LINE__, nAvail, p ); */ return p; }

      "

      echo "$STRNDUP_FUNC" >> src/libs/zbxdbupgrade/dbupgrade.c

      sed '/static void parse_db_monitor_item_params.*/ i\
      char *strndup( const char *s, size_t n );\
      ' src/libs/zbxdbupgrade/dbupgrade.c > src/libs/zbxdbupgrade/dbupgrade.c.new && mv src/libs/zbxdbupgrade/dbupgrade.c.new src/libs/zbxdbupgrade/dbupgrade.c

            Unassigned Unassigned
            omid.mt Omid Mehdizadeh
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: