[Asterisk-code-review] file.c/ ast file read dirs: Truncate path after calling stat (asterisk[14])

George Joseph asteriskteam at digium.com
Tue Nov 15 12:08:39 CST 2016


George Joseph has uploaded a new change for review. ( https://gerrit.asterisk.org/4445 )

Change subject: file.c/__ast_file_read_dirs:  Truncate path after calling stat
......................................................................

file.c/__ast_file_read_dirs:  Truncate path after calling stat

One of the code paths in __ast_file_read_dirs will only get executed if
the OS doesn't support dirent->d_type OR if the filesystem the
particular file is on doesn't support it.  So, while standard Linux
systems support the field, some filesystems like XFS do not.  In this
case, we need to call stat() to determine whether the directory entry
is a file or directory so we append the filename to the supplied
directory path and call stat.  We forgot to truncate path back to just
the directory afterwards though so we were passing a complete file name
to the callback in teh dir_name parameter instead of just the directory
name.

Change-Id: I54e4228bd8355fad65200c6df3ec4c9c8a98dfba
---
M main/file.c
1 file changed, 4 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/45/4445/1

diff --git a/main/file.c b/main/file.c
index 0239416..6d67ecf 100644
--- a/main/file.c
+++ b/main/file.c
@@ -1138,7 +1138,8 @@
 			/*
 			 * If using the stat function the file needs to be appended to the
 			 * path so it can be found. However, before appending make sure the
-			 * path contains only the directory for this depth level.
+			 * path contains only the directory for this depth level.  Then
+			 * we need to truncate it again after the stat.
 			 */
 			ast_str_truncate(*path, size);
 			ast_str_append(path, 0, "/%s", entry->d_name);
@@ -1146,12 +1147,14 @@
 			if (stat(ast_str_buffer(*path), &statbuf)) {
 				ast_log(LOG_ERROR, "Error reading path stats - %s: %s\n",
 					ast_str_buffer(*path), strerror(errno));
+				ast_str_truncate(*path, size);
 				/*
 				 * Output an error, but keep going. It could just be
 				 * a broken link and other files could be fine.
 				 */
 				continue;
 			}
+			ast_str_truncate(*path, size);
 
 			is_file = S_ISREG(statbuf.st_mode);
 			is_dir = S_ISDIR(statbuf.st_mode);

-- 
To view, visit https://gerrit.asterisk.org/4445
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I54e4228bd8355fad65200c6df3ec4c9c8a98dfba
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: George Joseph <gjoseph at digium.com>



More information about the asterisk-code-review mailing list