Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions system/nxpkg/pkg_manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,41 @@ static bool pkg_validate_hex(FAR const char *value)
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: pkg_validate_path_component
*
* Description:
* Check that a value is safe as one path component.
Comment thread
xiaoxiang781216 marked this conversation as resolved.
*
****************************************************************************/

bool pkg_validate_path_component(FAR const char *value)
{
FAR const char *p;

if (pkg_validate_required(value) < 0)
{
return false;
}

/* Reject dot names and parent traversal. */

if (value[0] == '.')
{
return false;
}

for (p = value; *p != '\0'; p++)
{
if (*p == '/' || *p == '\\')
{
return false;
}
}

return true;
}

const char *pkg_manifest_type_str(enum pkg_payload_type_e type)
{
switch (type)
Expand All @@ -95,6 +130,8 @@ const char *pkg_manifest_type_str(enum pkg_payload_type_e type)

int pkg_manifest_validate(FAR const struct pkg_manifest_s *manifest)
{
size_t i;

if (manifest == NULL)
{
return -EINVAL;
Expand All @@ -110,6 +147,14 @@ int pkg_manifest_validate(FAR const struct pkg_manifest_s *manifest)
return -EINVAL;
}

/* Names and versions become package-store path components. */

if (!pkg_validate_path_component(manifest->name) ||
!pkg_validate_path_component(manifest->version))
{
return -EINVAL;
}

if (strlen(manifest->sha256) != PKG_HASH_HEX_LEN)
{
return -EINVAL;
Expand All @@ -126,6 +171,19 @@ int pkg_manifest_validate(FAR const struct pkg_manifest_s *manifest)
return -EINVAL;
}

if (manifest->launch_argc > PKG_LAUNCH_ARGS_MAX)
{
return -EINVAL;
}

for (i = 0; i < manifest->launch_argc; i++)
{
if (pkg_validate_required(manifest->launch_args[i]) < 0)
{
return -EINVAL;
}
}

return 0;
}

Expand Down
Loading
Loading