Commit 73a5252d authored by Daan Vreeken's avatar Daan Vreeken
Browse files

Don't try to load directories as blocks.

When the .ctrl file contains a line to create an 'ec' block with incorrect
arguments, the following errors would be emitted :

 ERROR: Invalid arguments trying to create block 'ethercat'
 DEBUG: Load module 'ec' with prefix 'ethercat'
 ERROR: ec:1: syntax error, unexpected $end
 DEBUG: End of module 'ec': 1
 ERROR: pand.ctrl:50: Error creating block
 ERROR: Could not load controller file

The code would first try to load the dynamically loadable 'ec' block's module.
This would fail, because of incorrect arguments. controller_load_block_create()
would then try to stat() the file 'ec'. When found, it is opened and loaded as
a module block.
The code didn't check for the file to be a regular file and my build system
contains a directory with the name 'ec'. On FreeBSD, directories can be opened
and read as if they were regular files, but the .ctrl file parser would fail
to load the directory.
Change the code to *not* try to parse directories.

(It would be even better if we just stopped trying to load blocks when
controller_block_create() tells us that the block does exist, but the user has
made an error. At this moment though, controller_block_create() has no way of
telling the caller that.)

The new code bails out with :

 ERROR: Invalid arguments trying to create block 'ethercat'
 ERROR: Could not load or create block 'ec'
 ERROR: pand.ctrl:50: Error creating block
 ERROR: Could not load controller file

	modified:   controller/controller/controller_load.c
parent 062fc0fe
......@@ -286,7 +286,7 @@ static char *rel2file(yyscan_t scanner, char *rel_name)
char *tmp;
char *slash;
if (!stat(rel_name, &stattmp))
if ((stat(rel_name, &stattmp) == 0) && (!(stattmp.st_mode & S_IFDIR)))
return strdup(rel_name);
if (!extra->filename)
......@@ -300,7 +300,7 @@ static char *rel2file(yyscan_t scanner, char *rel_name)
asprintf(&ret, "%s/%s", tmp, rel_name);
free(tmp);
if (!stat(ret, &stattmp))
if ((stat(ret, &stattmp) == 0) && (!(stattmp.st_mode & S_IFDIR)))
return ret;
free(ret);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment