Skip to content

Fix #5, use path_max instead of os_max_file_name#23

Merged
jphickey merged 1 commit intonasa:masterfrom
avan989:new_new_fix_5
Oct 23, 2019
Merged

Fix #5, use path_max instead of os_max_file_name#23
jphickey merged 1 commit intonasa:masterfrom
avan989:new_new_fix_5

Conversation

@avan989
Copy link
Contributor

@avan989 avan989 commented Oct 7, 2019

Describe the contribution
Fix #5, used path_max instead of os_max_file_name.

Testing performed
Steps taken to test the contribution:

  1. Build
  2. Create sample_table.tbl file using elf2cfetbl. Used full path to trigger warning:
  3. Verify warning and that tbl file is still created.
Lenght of Source Filename + Path exceed OS_MAX_FILE_NAME
Lenght of Destination Filename + Path exceed OS_MAX_FILE_NAME
  1. Used sample_table.tbl file and verify it still work in cFS.

System(s) tested on:

  • Hardware
  • 18.04.03
  • cFE 6.7.0, elf2cfetbl 3.1.1

Contributor Info
Anh Van, NASA Goddard

Community contributors
You must attach a signed CLA (required for acceptance) or reference one already submitted

Copy link
Contributor

@jphickey jphickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple issues with this.

I disagree about checking against OS_MAX_FILE_NAME for two big reasons.

  1. This is a full path name on the HOST machine. The location of the file on the HOST can be very long and this has absolutely no relationship to its location once copied to a target. So warning if the HOST path exceeds OS_MAX_FILE_NAME doesn't add anything useful, it's just noise.

  2. This tool should not know what the osconfig.h of the target is, at all. We need to reduce dependencies on target-specific config here (I am going to file a separate bug about the inclusion of cfe_tbl_internal.h which should _not be required after the CFE pull request 27)

Also, I believe POSIX specifies that PATH_MAX is defined in limits.h. So one should #include <limits.h> not #include <linux/limits.h>. The former is POSIX-compliant but the latter, of course, will only work on Linux.

@skliper skliper added this to the 3.2.0 milestone Oct 8, 2019
@skliper
Copy link
Contributor

skliper commented Oct 8, 2019

A couple issues with this.

I disagree about checking against OS_MAX_FILE_NAME for two big reasons.

  1. This is a full path name on the HOST machine. The location of the file on the HOST can be very long and this has absolutely no relationship to its location once copied to a target. So warning if the HOST path exceeds OS_MAX_FILE_NAME doesn't add anything useful, it's just noise.

Disagree. Line in build is:

cd /home/jhageman/cFS/cFS-GitHub/build/cpu1/apps/sch_lab/tables_cpu1 && /home/jhageman/cFS/cFS-GitHub/build/tools/elf2cfetbl/elf2cfetbl sch_lab_table.o

This should warn if the name is too long, since the expectation when is this table should be loadable without any changes.

  1. This tool should not know what the osconfig.h of the target is, at all. We need to reduce dependencies on target-specific config here (I am going to file a separate bug about the inclusion of cfe_tbl_internal.h which should _not be required after the CFE pull request 27)

It needs to build tables that work with cFE, hence it's by design dependent on cFE settings. Feel free to suggest alternatives, but this warning has purpose.

Also, I believe POSIX specifies that PATH_MAX is defined in limits.h. So one should #include <limits.h> not #include <linux/limits.h>. The former is POSIX-compliant but the latter, of course, will only work on Linux.

Agreed.

@jphickey
Copy link
Contributor

jphickey commented Oct 8, 2019

This is a full path name on the HOST machine. The location of the file on the HOST can be very long and this has absolutely no relationship to its location once copied to a target. So warning if the HOST path exceeds OS_MAX_FILE_NAME doesn't add anything useful, it's just noise.

Disagree. Line in build is:

cd /home/jhageman/cFS/cFS-GitHub/build/cpu1/apps/sch_lab/tables_cpu1 && /home/jhageman/cFS/cFS-GitHub/build/tools/elf2cfetbl/elf2cfetbl sch_lab_table.o

This should warn if the name is too long, since the expectation when is this table should be loadable without any changes.

That is only an artifact of how the build system happens to currently invoke it as part of the current/default build process, because it "cd'd" into the directory first and then ran the tool so it therefore didn't need to specify any relative path to the file.... If you run this from the command line or otherwise write your own Makefile to generate a table (as many do), or even if the CMake recipe changes in the future then this can be a full path name to the source file.

That particular method of invocation is not a requirement and not guaranteed to remain consistent in the future.

I thought this was the whole reason for changing from OS_MAX_FILE_NAME to PATH_MAX -- because it is a host-side tool and this is storing a host-side path name, so OS_MAX_FILE_NAME is irrelevant here.

This tool should not know what the osconfig.h of the target is, at all. We need to reduce dependencies on target-specific config here (I am going to file a separate bug about the inclusion of cfe_tbl_internal.h which should _not be required after the CFE pull request 27)

It needs to build tables that work with cFE, hence it's by design dependent on cFE settings. Feel free to suggest alternatives, but this warning has purpose.

But CFE doesn't have a definition for this, OSAL does. And it can be different on every CPU, and elf2cfetbl doesn't know which CPU it is actually generating a table for.

@skliper
Copy link
Contributor

skliper commented Oct 8, 2019

That particular method of invocation is not a requirement and not guaranteed to remain consistent in the future.
...
I thought this was the whole reason for changing from OS_MAX_FILE_NAME to PATH_MAX -- because it is a host-side tool and this is storing a host-side path name, so OS_MAX_FILE_NAME is irrelevant here.
...
But CFE doesn't have a definition for this, OSAL does. And it can be different on every CPU, and elf2cfetbl doesn't know which CPU it is actually generating a table for.

Understood it's not perfect, and if build system or invocation changes it may be a false warning but in our current context it's useful for us and not an error.

EDIT: By "not an error" I mean feel free to > /dev/null if you want to ignore it, it'll still work.

@jphickey
Copy link
Contributor

jphickey commented Oct 8, 2019

It is more than just not perfect, it's not correct. Perhaps I didn't express that clearly enough...

  • It is validating/checking something that happens to work today only by mere coincidence.
  • It is checking both the source and destination files, where only the destination file name length even remotely matters (because this is the one that gets put on the target, not the source file).
  • It is checking the entire path name against OS_MAX_FILE_NAME -- which is wrong -- this is a path name so it should be OS_MAX_PATH_NAME (but not, because its a host path name)
  • The actual file name part (the one that would be validated against OS_MAX_FILE_NAME) is ALREADY guaranteed to be less than the maximum size, because it is stored in the TblFileDef object in a limited-size buffer.

In other words, the validation you are looking for (that the actual filename part is less than the size limit) is already done, and this extra check is both superfluous and wrong.

To make it even more problematic, this will start to trigger a compiler error once merged with the other cleanup, when you (rightfully) cannot include osconfig.h anymore, because the hacks are taken out.

@skliper
Copy link
Contributor

skliper commented Oct 8, 2019

  • The actual file name part (the one that would be validated against OS_MAX_FILE_NAME) is ALREADY guaranteed to be less than the maximum size, because it is stored in the TblFileDef object in a limited-size buffer.

Good point. I was thrown off by the destination directory command line option, which just gets appended to.

In other words, the validation you are looking for (that the actual filename part is less than the size limit) is already done...

And that's what I needed to hear! I'm on board with just taking out the warnings now.

@avan989
Copy link
Contributor Author

avan989 commented Oct 9, 2019

removed warning, osconfig.h and changed to linux.h. Tested with sample_table, still work.

Copy link
Contributor

@skliper skliper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it PATH_MAX-1 in the strncpys, otherwise could end up unterminated.

@avan989
Copy link
Contributor Author

avan989 commented Oct 9, 2019

update to path_max -1

Copy link
Contributor

@jphickey jphickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now

@skliper skliper changed the title Fix #5, use path_max while warning if exceed os_max_file_name Fix #5, use path_max instead of os_max_file_name Oct 10, 2019
@skliper skliper added the CCB:Approved Indicates code approval by CCB label Oct 10, 2019
jphickey added a commit that referenced this pull request Oct 11, 2019
Merge branches 'pull-15', 'pull-20', 'pull-21', 'pull-23'
and 'pull-24' for integration
@jphickey jphickey merged commit b7dcc71 into nasa:master Oct 23, 2019
@skliper skliper modified the milestone: 3.2.0 Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CCB:Approved Indicates code approval by CCB

Projects

None yet

Development

Successfully merging this pull request may close these issues.

elf2cfetbl internal filename/path length dependency on OSAL questionable

3 participants