[ZBX-7013] non-standard strndup is used in dbupgrade.c file, DBpatch_2010101 function Created: 2013 Sep 16  Updated: 2017 May 30  Resolved: 2013 Sep 19

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S)
Affects Version/s: 2.1.4
Fix Version/s: 2.2.0

Type: Incident report Priority: Minor
Reporter: Omid Mehdizadeh Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Solaris x86, Sun Studio 12



 Description   

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



 Comments   
Comment by Igors Homjakovs (Inactive) [ 2013 Sep 18 ]

Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-7013

Comment by Alexander Vladishev [ 2013 Sep 18 ]

(1) Please remove incorrectly created svn://svn.zabbix.com/branches/dev/ZBX-7013/trunk branch.

igorsh RESOLVED in r38645

sasha CLOSED

Comment by Alexander Vladishev [ 2013 Sep 18 ]

(2) "size" and "offset" variables should be renamed to "param_alloc" and "param_offset" for consistency.

igorsh RESOLVED in r38646

sasha CLOSED

Comment by Alexander Vladishev [ 2013 Sep 19 ]

(3) Please review my fix in r38618.

igorsh Minor code fix in r38648

RESOLVED

sasha Thanks! CLOSED

Comment by Alexander Vladishev [ 2013 Sep 19 ]

Successfully tested!

Comment by Igors Homjakovs (Inactive) [ 2013 Sep 23 ]

Fixed in trunk r38732

Generated at Wed Apr 24 22:47:59 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.