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

Kevin Harwell asteriskteam at digium.com
Tue Nov 15 17:19:38 CST 2016


Kevin Harwell has posted comments on this change. ( https://gerrit.asterisk.org/4447 )

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


Patch Set 3: Code-Review-1

(3 comments)

https://gerrit.asterisk.org/#/c/4447/3/main/file.c
File main/file.c:

PS3, Line 1145: 			if (stat(ast_str_buffer(*path), &statbuf)) {
              : 				ast_log(LOG_ERROR, "Error reading path stats - %s: %s\n",
              : 					ast_str_buffer(*path), strerror(errno));
              : 				/*
              : 				 * Output an error, but keep going. It could just be
              : 				 * a broken link and other files could be fine.
              : 				 */
              : 				continue;
              : 			}
If this off nominal path gets triggered then 'path' has the d_name attached. If on the next iteration the stat function is not used then this entry doesn't get truncated and would cause problems in the directory case (double append).

A truncate near the beginning of the while loop might fix this case though.


PS3, Line 1176: 		if (!is_dir) {
              : 			ast_debug(5, "Skipping %s: not a regular file or directory\n",
              : 				  ast_str_buffer(*path));
              : 			continue;
              : 		}
If it is not a directory or file and the stat function was used then whatever it was got appended and needs to be removed just in case the next iteration doesn't use the stat function.

A truncate near the beginning of the while loop might fix this case though.


PS3, Line 1188: 			if (!used_stat) {
              : 				ast_str_append(path, 0, "/%s", entry->d_name);
I think a truncate still needs to be done here before appending the directory. Consider the case where the directory gets appended. If the next iteration is also a directory and it didn't require the stat function then this will append onto the previously added sub-directory.

Either that or you might be able to remove the first call to truncate (the one after the stat function) and just add a single truncate call near the beginning of the while loop (maybe after the first 'if' check)?

Note, adding it near the beginning of the loop should also cover the case where it is neither a directory or file too and/or other off nominal paths.


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I54e4228bd8355fad65200c6df3ec4c9c8a98dfba
Gerrit-PatchSet: 3
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-HasComments: Yes



More information about the asterisk-code-review mailing list