GUACAMOLE-637: Add RDP filesystem and SFTP unit tests for path depth.
This commit is contained in:
parent
6e2be38ae2
commit
cda7bca126
@ -164,7 +164,8 @@ void test_fs__normalize_relative_mixed() {
|
||||
*
|
||||
* @param length
|
||||
* The number of bytes to include in the generated path, not counting the
|
||||
* null-terminator.
|
||||
* null-terminator. If -1, the length of the path will be automatically
|
||||
* determined from the provided max_depth.
|
||||
*
|
||||
* @param max_depth
|
||||
* The maximum number of path components to include within the generated
|
||||
@ -177,6 +178,10 @@ void test_fs__normalize_relative_mixed() {
|
||||
*/
|
||||
static char* generate_path(int length, int max_depth) {
|
||||
|
||||
/* If no length given, calculate space required from max_depth */
|
||||
if (length == -1)
|
||||
length = max_depth * 2;
|
||||
|
||||
int i;
|
||||
char* input = malloc(length + 1);
|
||||
|
||||
@ -207,7 +212,7 @@ void test_fs__normalize_long() {
|
||||
char normalized[GUAC_COMMON_SSH_SFTP_MAX_PATH];
|
||||
|
||||
/* Exceeds maximum length by a factor of 2 */
|
||||
input = generate_path(GUAC_COMMON_SSH_SFTP_MAX_PATH*2, GUAC_COMMON_SSH_SFTP_MAX_DEPTH);
|
||||
input = generate_path(GUAC_COMMON_SSH_SFTP_MAX_PATH * 2, GUAC_COMMON_SSH_SFTP_MAX_DEPTH);
|
||||
CU_ASSERT_EQUAL(guac_common_ssh_sftp_normalize_path(normalized, input), 0);
|
||||
free(input);
|
||||
|
||||
@ -223,3 +228,36 @@ void test_fs__normalize_long() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test which verifies that paths exceeding the maximum path depth are
|
||||
* rejected.
|
||||
*/
|
||||
void test_fs__normalize_deep() {
|
||||
|
||||
char* input;
|
||||
char normalized[GUAC_COMMON_SSH_SFTP_MAX_PATH];
|
||||
|
||||
/* Exceeds maximum depth by a factor of 2 */
|
||||
input = generate_path(-1, GUAC_COMMON_SSH_SFTP_MAX_DEPTH * 2);
|
||||
CU_ASSERT_EQUAL(guac_common_ssh_sftp_normalize_path(normalized, input), 0);
|
||||
free(input);
|
||||
|
||||
/* Exceeds maximum depth by one component */
|
||||
input = generate_path(-1, GUAC_COMMON_SSH_SFTP_MAX_DEPTH + 1);
|
||||
CU_ASSERT_EQUAL(guac_common_ssh_sftp_normalize_path(normalized, input), 0);
|
||||
free(input);
|
||||
|
||||
/* Exactly maximum depth (should still be rejected as SFTP depth limits are
|
||||
* set such that a path with the maximum depth will exceed the maximum
|
||||
* length) */
|
||||
input = generate_path(-1, GUAC_COMMON_SSH_SFTP_MAX_DEPTH);
|
||||
CU_ASSERT_EQUAL(guac_common_ssh_sftp_normalize_path(normalized, input), 0);
|
||||
free(input);
|
||||
|
||||
/* Less than maximum depth */
|
||||
input = generate_path(-1, GUAC_COMMON_SSH_SFTP_MAX_DEPTH - 1);
|
||||
CU_ASSERT_NOT_EQUAL(guac_common_ssh_sftp_normalize_path(normalized, input), 0);
|
||||
free(input);
|
||||
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,8 @@ void test_fs__normalize_relative_mixed() {
|
||||
*
|
||||
* @param length
|
||||
* The number of bytes to include in the generated path, not counting the
|
||||
* null-terminator.
|
||||
* null-terminator. If -1, the length of the path will be automatically
|
||||
* determined from the provided max_depth.
|
||||
*
|
||||
* @param max_depth
|
||||
* The maximum number of path components to include within the generated
|
||||
@ -177,6 +178,10 @@ void test_fs__normalize_relative_mixed() {
|
||||
*/
|
||||
static char* generate_path(int length, int max_depth) {
|
||||
|
||||
/* If no length given, calculate space required from max_depth */
|
||||
if (length == -1)
|
||||
length = max_depth * 2;
|
||||
|
||||
int i;
|
||||
char* input = malloc(length + 1);
|
||||
|
||||
@ -207,7 +212,7 @@ void test_fs__normalize_long() {
|
||||
char normalized[GUAC_RDP_FS_MAX_PATH];
|
||||
|
||||
/* Exceeds maximum length by a factor of 2 */
|
||||
input = generate_path(GUAC_RDP_FS_MAX_PATH*2, GUAC_RDP_MAX_PATH_DEPTH);
|
||||
input = generate_path(GUAC_RDP_FS_MAX_PATH * 2, GUAC_RDP_MAX_PATH_DEPTH);
|
||||
CU_ASSERT_NOT_EQUAL(guac_rdp_fs_normalize_path(input, normalized), 0);
|
||||
free(input);
|
||||
|
||||
@ -223,3 +228,29 @@ void test_fs__normalize_long() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test which verifies that paths exceeding the maximum path depth are
|
||||
* rejected.
|
||||
*/
|
||||
void test_fs__normalize_deep() {
|
||||
|
||||
char* input;
|
||||
char normalized[GUAC_RDP_FS_MAX_PATH];
|
||||
|
||||
/* Exceeds maximum depth by a factor of 2 */
|
||||
input = generate_path(-1, GUAC_RDP_MAX_PATH_DEPTH * 2);
|
||||
CU_ASSERT_NOT_EQUAL(guac_rdp_fs_normalize_path(input, normalized), 0);
|
||||
free(input);
|
||||
|
||||
/* Exceeds maximum depth by one component */
|
||||
input = generate_path(-1, GUAC_RDP_MAX_PATH_DEPTH + 1);
|
||||
CU_ASSERT_NOT_EQUAL(guac_rdp_fs_normalize_path(input, normalized), 0);
|
||||
free(input);
|
||||
|
||||
/* Exactly maximum depth */
|
||||
input = generate_path(-1, GUAC_RDP_MAX_PATH_DEPTH);
|
||||
CU_ASSERT_EQUAL(guac_rdp_fs_normalize_path(input, normalized), 0);
|
||||
free(input);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user