-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os_dirent_t.FileName uses OS_MAX_PATH_LEN for array size #344
Comments
This issue was filed by Steven Seeger @ GSFC |
Link to code: osal/src/os/inc/osapi-os-filesys.h Lines 189 to 193 in 7d9c4c8
|
Are directory names under the same limit, or at least reported directory names from DirRead? I see sample config OS_MAX_FILE_NAME is 20, OS_MAX_PATH_LEN is 64. The default_osconfig.h doesn't really specify the file name length applies to directory names, maybe it should? OS_mkdir just takes a char *, no internal limiting in vxworks implementation. |
Further digging - OS_mkdir limit is OS_MAX_PATH_LEN. OS_OpenCreate checks both OS_MAX_PATH_LEN and OS_MAX_FILE_NAME. Looks like in that context (directory name can be bigger than OS_MAX_FILE_NAME) the current definition is consistent. Plan to just add a comment to that effect to resolve this issue. |
I think the bug report is valid - definition of this struct should use OS_MAX_FILE_NAME, not OS_MAX_PATH_LEN. OS_MAX_PATH_LEN is the maximum length of a full path/absolute file name which has both pathname component and a file name component whereas the OS_MAX_FILE_NAME is the limit for just the filename component. The "readdir" function returns just file names, so the latter is the better length. Using OS_MAX_PATH_LEN just means the buffer is bigger than it needs to be. (better than being too small, I guess - there shouldn't be a risk of overrun here but it just uses extra memory). |
|
But OS_mkdir doesn't limit individual directory name lengths so you could make a directory name longer than OS_MAX_FILE_NAME, but then the name would be truncated if you readdir... |
There is no limit I could find other than OS_MAX_PATH_LEN on a directory name... if there is please provide a link to code. |
In other words, OS_mkdir doesn't limit each individual directory name with OS_MAX_FILE_NAME just the absolute path. If it's just one deep, could create a directory name of that full length, so why would we limit readdir? |
Yeah, that's possibly another bug, then.... The helper function osal/src/os/shared/osapi-file.c Lines 67 to 90 in 7d9c4c8
(Interestingly, it looks like this is using Most file ops seem to employ this function, but its missing on some, which is probably not correct. An alternative that might be simpler AND more complete -- This same test could probably be done as part of OS_TranslatePath, as I would think anything doing path translation (incl mkdir) should be checking this limit. |
Yes, sounds like a good change to me. Add to OS_TranslatePath and remove where now redundant (OS_rename, OS_OpenCreate, OS_remove). Then covers every file/dir access and limits dir names to OS_MAX_FILE_NAME (with the comparison update). |
After thinking about it a bit more, my only concern with doing this in OS_TranslatePath is if a file was created outside OSAL that didn't meet this limit (such as from the shell) then it would be become completely "non-accessible" from OSAL, even for removal or rename operations. But since due to the translations the name as to fit within OS_MAX_LOCAL_PATH_LEN regardless.... so maybe that is acceptable behavior. |
Changes FileName in os_dirent_t from OS_MAX_PATH_LEN to OS_MAX_FILE_NAME, and moves OS_check_name_length into OS_TranslatePath so it is consistantly applied everywhere. Also fixes the length checks in OS_check_name_length to account for terminating null. Unit tests updated to match new directory name limit.
Changes FileName in os_dirent_t from OS_MAX_PATH_LEN to OS_MAX_FILE_NAME, and moves OS_check_name_length into OS_TranslatePath so it is consistantly applied everywhere. Also fixes the length checks in OS_check_name_length to account for terminating null. Unit tests updated to match new directory name limit.
Changes FileName in os_dirent_t from OS_MAX_PATH_LEN to OS_MAX_FILE_NAME, and moves OS_check_name_length into OS_TranslatePath so it is consistantly applied everywhere. Also fixes the length checks in OS_check_name_length to account for terminating null. Unit tests updated to match new directory name limit. Coverage tests updated to match simplified logic.
Fix #344, Consistent directory entry size limit
Changes FileName in os_dirent_t from OS_MAX_PATH_LEN to OS_MAX_FILE_NAME, and moves OS_check_name_length into OS_TranslatePath so it is consistantly applied everywhere. Also fixes the length checks in OS_check_name_length to account for terminating null. Unit tests updated to match new directory name limit. Coverage tests updated to match simplified logic.
Fix nasa#344, Remove mission/platform include dirs
typedef struct
{
char FileName[OS_MAX_PATH_LEN];
} os_dirent_t;
It's probably the case that FileName should be of OS_MAX_FILE_NAME size instead.
The use case is to build a filename from a path and a filename from an os_dirent_t. This path, including the filename, would be OS_MAX_PATH_LEN.
The text was updated successfully, but these errors were encountered: