File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -687,33 +687,19 @@ char *MCS_resolvepath(const char *path)
687687 struct stat64 buf;
688688 if (lstat64 (tildepath, &buf) != 0 || !S_ISLNK (buf.st_mode ))
689689 return tildepath;
690- int4 size;
691- char *newname = new char [PATH_MAX + 2 ];
692- if ((size = readlink (tildepath, newname, PATH_MAX)) < 0 )
693- {
694- delete tildepath;
695- delete newname;
696- return NULL ;
697- }
698- delete tildepath;
699- newname[size] = ' \0 ' ;
700- if (newname[0 ] != ' /' )
701- {
702- char *fullpath = new char [strlen (path) + strlen (newname) + 2 ];
703- strcpy (fullpath, path);
704- char *sptr = strrchr (fullpath, ' /' );
705- if (sptr == NULL )
706- sptr = fullpath;
707- else
708- sptr++;
709- strcpy (sptr, newname);
710- delete newname;
711- // SN-2015-06-05: [[ Bug 15432 ]] Calling MCS_resolvepath ensures that
712- // we will get an absolute path here, if any
713- newname = MCS_resolvepath (fullpath);
714- delete fullpath;
715- }
716- return newname;
690+
691+ char *newname = new char [PATH_MAX + 2 ];
692+
693+ // SN-2015-06-05: [[ Bug 15432 ]] Use realpath to solve the symlink.
694+ if (realpath (tildepath, newname) == NULL )
695+ {
696+ // Clear the memory in case of failure
697+ delete newname;
698+ newname = NULL ;
699+ }
700+
701+ delete tildepath;
702+ return newname;
717703}
718704
719705char *MCS_get_canonical_path (const char *p_path)
Original file line number Diff line number Diff line change @@ -2440,31 +2440,19 @@ char *MCS_resolvepath(const char *path)
24402440 struct stat buf;
24412441 if (lstat (tildepath, &buf) != 0 || !S_ISLNK (buf.st_mode ))
24422442 return tildepath;
2443- int4 size;
2444- char *newname = new char [PATH_MAX + 2 ];
2445- if ((size = readlink (tildepath, newname, PATH_MAX)) < 0 )
2446- {
2447- delete tildepath;
2448- delete newname;
2449- return NULL ;
2450- }
2451- delete tildepath;
2452- newname[size] = ' \0 ' ;
2453- if (newname[0 ] != ' /' )
2454- {
2455- char *fullpath = new char [strlen (path) + strlen (newname) + 2 ];
2456- strcpy (fullpath, path);
2457- char *sptr = strrchr (fullpath, ' /' );
2458- if (sptr == NULL )
2459- sptr = fullpath;
2460- else
2461- sptr++;
2462- strcpy (sptr, newname);
2463- delete newname;
2464- newname = MCS_resolvepath (fullpath);
2465- delete fullpath;
2466- }
2467- return newname;
2443+
2444+ char *newname = new char [PATH_MAX + 2 ];
2445+
2446+ // SN-2015-06-05: [[ Bug 15432 ]] Use realpath to solve the symlink.
2447+ if (realpath (tildepath, newname) == NULL )
2448+ {
2449+ // Clear the memory in case of failure
2450+ delete newname;
2451+ newname = NULL ;
2452+ }
2453+
2454+ delete tildepath;
2455+ return newname;
24682456}
24692457
24702458Boolean MCS_rename (const char *oname, const char *nname)
You can’t perform that action at this time.
0 commit comments