Skip to content

Commit

Permalink
Avoid casting away const when not needed
Browse files Browse the repository at this point in the history
Silences a clang warning.

No functional change intended.

(cherry picked from commit 0070e55)
  • Loading branch information
DemiMarie authored and marmarek committed Jun 22, 2024
1 parent edf98b8 commit f1e5736
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
10 changes: 5 additions & 5 deletions qrexec-lib/unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void process_one_file_reg(struct file_header *untrusted_hdr,
const char *last_segment;
char *path_dup;

if (!qubes_pure_validate_file_name((uint8_t *)untrusted_name))
if (!qubes_pure_validate_file_name((const uint8_t *)untrusted_name))
do_exit(EILSEQ, untrusted_name); /* FIXME: better error message */
if ((path_dup = strdup(untrusted_name)) == NULL)
do_exit(ENOMEM, untrusted_name);
Expand Down Expand Up @@ -266,7 +266,7 @@ void process_one_file_dir(struct file_header *untrusted_hdr,
int safe_dirfd;
const char *last_segment;
char *path_dup;
if (!qubes_pure_validate_file_name((uint8_t *)untrusted_name))
if (!qubes_pure_validate_file_name((const uint8_t *)untrusted_name))
do_exit(EILSEQ, untrusted_name); /* FIXME: better error message */
if ((path_dup = strdup(untrusted_name)) == NULL)
do_exit(ENOMEM, untrusted_name);
Expand Down Expand Up @@ -298,7 +298,7 @@ void process_one_file_link(struct file_header *untrusted_hdr,
const char *last_segment;
char *path_dup;
unsigned int filelen;
if (!qubes_pure_validate_file_name((uint8_t *)untrusted_name))
if (!qubes_pure_validate_file_name((const uint8_t *)untrusted_name))
do_exit(EILSEQ, untrusted_name); /* FIXME: better error message */
int safe_dirfd;
if (untrusted_hdr->filelen > MAX_PATH_LENGTH - 1)
Expand All @@ -315,8 +315,8 @@ void process_one_file_link(struct file_header *untrusted_hdr,
* Ensure that no immediate subdirectory of ~/QubesIncoming/VMNAME
* may have symlinks that point out of it.
*/
if (!qubes_pure_validate_symbolic_link((uint8_t *)untrusted_name,
(uint8_t *)untrusted_content))
if (!qubes_pure_validate_symbolic_link((const uint8_t *)untrusted_name,
(const uint8_t *)untrusted_content))
do_exit(EILSEQ, untrusted_content);

if ((path_dup = strdup(untrusted_name)) == NULL)
Expand Down
40 changes: 20 additions & 20 deletions qrexec-lib/validator-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,34 @@ int main(int argc, char **argv)
{
(void)argc;
(void)argv;
assert(qubes_pure_validate_file_name((uint8_t *)u8"simple_safe_filename.txt"));
assert(qubes_pure_validate_file_name((const uint8_t *)u8"simple_safe_filename.txt"));

// Directory traversal checks
assert(!qubes_pure_validate_file_name((uint8_t *)".."));
assert(!qubes_pure_validate_file_name((uint8_t *)"../.."));
assert(!qubes_pure_validate_file_name((uint8_t *)"a/.."));
assert(!qubes_pure_validate_file_name((uint8_t *)"a/../b"));
assert(!qubes_pure_validate_file_name((uint8_t *)"/"));
assert(!qubes_pure_validate_file_name((uint8_t *)"//"));
assert(!qubes_pure_validate_file_name((uint8_t *)"///"));
assert(!qubes_pure_validate_file_name((uint8_t *)"/a"));
assert(!qubes_pure_validate_file_name((uint8_t *)"//a"));
assert(!qubes_pure_validate_file_name((uint8_t *)"///a"));
assert(!qubes_pure_validate_file_name((const uint8_t *)".."));
assert(!qubes_pure_validate_file_name((const uint8_t *)"../.."));
assert(!qubes_pure_validate_file_name((const uint8_t *)"a/.."));
assert(!qubes_pure_validate_file_name((const uint8_t *)"a/../b"));
assert(!qubes_pure_validate_file_name((const uint8_t *)"/"));
assert(!qubes_pure_validate_file_name((const uint8_t *)"//"));
assert(!qubes_pure_validate_file_name((const uint8_t *)"///"));
assert(!qubes_pure_validate_file_name((const uint8_t *)"/a"));
assert(!qubes_pure_validate_file_name((const uint8_t *)"//a"));
assert(!qubes_pure_validate_file_name((const uint8_t *)"///a"));

// No repeated slashes
assert(!qubes_pure_validate_file_name((uint8_t *)"a//b"));
assert(!qubes_pure_validate_file_name((const uint8_t *)"a//b"));

// No "." as a path component
assert(!qubes_pure_validate_file_name((uint8_t *)"."));
assert(!qubes_pure_validate_file_name((uint8_t *)"a/."));
assert(!qubes_pure_validate_file_name((uint8_t *)"./a"));
assert(!qubes_pure_validate_file_name((uint8_t *)"a/./a"));
assert(!qubes_pure_validate_file_name((const uint8_t *)"."));
assert(!qubes_pure_validate_file_name((const uint8_t *)"a/."));
assert(!qubes_pure_validate_file_name((const uint8_t *)"./a"));
assert(!qubes_pure_validate_file_name((const uint8_t *)"a/./a"));

// No ".." as a path component
assert(!qubes_pure_validate_file_name((uint8_t *)".."));
assert(!qubes_pure_validate_file_name((uint8_t *)"a/.."));
assert(!qubes_pure_validate_file_name((uint8_t *)"../a"));
assert(!qubes_pure_validate_file_name((uint8_t *)"a/../a"));
assert(!qubes_pure_validate_file_name((const uint8_t *)".."));
assert(!qubes_pure_validate_file_name((const uint8_t *)"a/.."));
assert(!qubes_pure_validate_file_name((const uint8_t *)"../a"));
assert(!qubes_pure_validate_file_name((const uint8_t *)"a/../a"));

// Looks like "." or ".." but is not
assert(qubes_pure_validate_file_name((const uint8_t *)".a"));
Expand Down

0 comments on commit f1e5736

Please sign in to comment.