Pārlūkot izejas kodu

Merge trunk revision 2962:
r2962 | honzaf | 2010-06-23 01:39:49 -0700 (Wed, 23 Jun 2010) | 13 lines

Remove pathconf which may fall

Corosync has problem with readdir_r if pathconf function fails.

Main problem is hidden in calling pathconf (internally calls statfs)
which may fail. After this fail, newly allocated memory for readdir_r
was smaller than expected and memory was overwritten by readdir_r.

Patch removes calling of pathconf and rather use NAME_MAX constant which
is always large enough for all file systems.

Also return value of malloc SHOULD be checked.



git-svn-id: http://svn.fedorahosted.org/svn/corosync/branches/flatiron@2968 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake 15 gadi atpakaļ
vecāks
revīzija
7323d1c054
1 mainītis faili ar 10 papildinājumiem un 4 dzēšanām
  1. 10 4
      exec/coroparse.c

+ 10 - 4
exec/coroparse.c

@@ -278,9 +278,12 @@ static int read_uidgid_files_into_objdb(
 	if (dp == NULL)
 		return 0;
 
-	len = offsetof(struct dirent, d_name) +
-                     pathconf(dirname, _PC_NAME_MAX) + 1;
+	len = offsetof(struct dirent, d_name) + NAME_MAX + 1;
+
 	entry = malloc(len);
+	if (entry == NULL) {
+		return 0;
+	}
 
 	for (return_code = readdir_r(dp, entry, &dirent);
 		dirent != NULL && return_code == 0;
@@ -331,9 +334,12 @@ static int read_service_files_into_objdb(
 	if (dp == NULL)
 		return 0;
 
-	len = offsetof(struct dirent, d_name) +
-                     pathconf(dirname, _PC_NAME_MAX) + 1;
+	len = offsetof(struct dirent, d_name) + NAME_MAX + 1;
+
 	entry = malloc(len);
+	if (entry == NULL) {
+		return 0;
+	}
 
 	for (return_code = readdir_r(dp, entry, &dirent);
 		dirent != NULL && return_code == 0;