Saturday, 15 August 2015

unix - strcat dumping core in SunOS -



unix - strcat dumping core in SunOS -

i have programme goes through directory construction , concatenates files nowadays in path szfile . have used dirent here directory entries. dumping core in strcat function within loop in sunos . goes through fine in hp , aix machine .

#include <stdio.h> #include <string.h> #include <dirent.h> #include <limits.h> #include <sys/types.h> int main() { dir *pdirhand; char szfile[1024]; struct dirent pdirent ; struct dirent *presult = null; char *sdir = "fullpath"; /* fullpath can /make/users/path */ strncpy (szfile, sdir, sizeof(szfile)-1); szfile[sizeof(szfile)-1] = '\0'; if (null == (pdirhand = opendir(szfile))) { homecoming -1; } for(readdir_r(pdirhand, &pdirent, &presult); presult != 0;readdir_r(pdirhand, &pdirent, &presult)) { file *fp; fp=fopen("debug.log","a+"); strcpy (szfile, sdir); strcat (szfile, "/"); strcat (szfile, pdirent.d_name); } if (pdirhand) closedir (pdirhand); homecoming 0; }

i dont have files in path assign sdir. has "." , ".." directory entries in core dump in line

strcat (szfile, pdirent.d_name);

i had used dbx find out value of szfile , during sec iteration value exceeding memory allocated . value comes

"fullpath/../fullpath/../fullpath/../fullpath/../fullpath/..fullpath/..fullpath/../../../../../../fullpath/../fullpath/../fullpath/../fullpath/../fullpath/../fullpath/../fullpath/../fullpath/../fullpath/../fullpath/..fullpath/../fullpath/../fullpath/../fullpath/../fullpath/../fullpath/../fullpath/../fullpath/../fullpath/../fullpath/.." ...

i have tried using strlcat , concatinated value of szfile not coming properly. faced problem in sunos or can help ?

unix segmentation-fault strcat sunos

No comments:

Post a Comment