GUACAMOLE-637: Add path depth limits to generated paths in unit tests.
This commit is contained in:
parent
986f7f5d64
commit
6e2be38ae2
@ -166,19 +166,28 @@ void test_fs__normalize_relative_mixed() {
|
||||
* The number of bytes to include in the generated path, not counting the
|
||||
* null-terminator.
|
||||
*
|
||||
* @param max_depth
|
||||
* The maximum number of path components to include within the generated
|
||||
* path.
|
||||
*
|
||||
* @return
|
||||
* A dynamically-allocated path containing the given number of bytes, not
|
||||
* counting the null-terminator. This path must eventually be freed with a
|
||||
* call to free().
|
||||
*/
|
||||
static char* generate_path(int length) {
|
||||
static char* generate_path(int length, int max_depth) {
|
||||
|
||||
int i;
|
||||
char* input = malloc(length + 1);
|
||||
|
||||
/* Fill path with /x/x/x/x/x/x/x/x/x/x/... */
|
||||
/* Fill path with /x/x/x/x/x/x/x/x/x/x/.../xxxxxxxxx... */
|
||||
for (i = 0; i < length; i++) {
|
||||
input[i] = (i % 2 == 0) ? '/' : 'x';
|
||||
if (max_depth > 0 && i % 2 == 0) {
|
||||
input[i] = '/';
|
||||
max_depth--;
|
||||
}
|
||||
else
|
||||
input[i] = 'x';
|
||||
}
|
||||
|
||||
/* Add null terminator */
|
||||
@ -198,17 +207,17 @@ 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);
|
||||
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);
|
||||
|
||||
/* Exceeds maximum length by one byte */
|
||||
input = generate_path(GUAC_COMMON_SSH_SFTP_MAX_PATH);
|
||||
input = generate_path(GUAC_COMMON_SSH_SFTP_MAX_PATH, GUAC_COMMON_SSH_SFTP_MAX_DEPTH);
|
||||
CU_ASSERT_EQUAL(guac_common_ssh_sftp_normalize_path(normalized, input), 0);
|
||||
free(input);
|
||||
|
||||
/* Exactly maximum length */
|
||||
input = generate_path(GUAC_COMMON_SSH_SFTP_MAX_PATH - 1);
|
||||
input = generate_path(GUAC_COMMON_SSH_SFTP_MAX_PATH - 1, GUAC_COMMON_SSH_SFTP_MAX_DEPTH);
|
||||
CU_ASSERT_NOT_EQUAL(guac_common_ssh_sftp_normalize_path(normalized, input), 0);
|
||||
free(input);
|
||||
|
||||
|
@ -166,19 +166,28 @@ void test_fs__normalize_relative_mixed() {
|
||||
* The number of bytes to include in the generated path, not counting the
|
||||
* null-terminator.
|
||||
*
|
||||
* @param max_depth
|
||||
* The maximum number of path components to include within the generated
|
||||
* path.
|
||||
*
|
||||
* @return
|
||||
* A dynamically-allocated path containing the given number of bytes, not
|
||||
* counting the null-terminator. This path must eventually be freed with a
|
||||
* call to free().
|
||||
*/
|
||||
static char* generate_path(int length) {
|
||||
static char* generate_path(int length, int max_depth) {
|
||||
|
||||
int i;
|
||||
char* input = malloc(length + 1);
|
||||
|
||||
/* Fill path with \x\x\x\x\x\x\x\x\x\x\... */
|
||||
/* Fill path with \x\x\x\x\x\x\x\x\x\x\...\xxxxxxxxx... */
|
||||
for (i = 0; i < length; i++) {
|
||||
input[i] = (i % 2 == 0) ? '\\' : 'x';
|
||||
if (max_depth > 0 && i % 2 == 0) {
|
||||
input[i] = '\\';
|
||||
max_depth--;
|
||||
}
|
||||
else
|
||||
input[i] = 'x';
|
||||
}
|
||||
|
||||
/* Add null terminator */
|
||||
@ -198,17 +207,17 @@ 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);
|
||||
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);
|
||||
|
||||
/* Exceeds maximum length by one byte */
|
||||
input = generate_path(GUAC_RDP_FS_MAX_PATH);
|
||||
input = generate_path(GUAC_RDP_FS_MAX_PATH, GUAC_RDP_MAX_PATH_DEPTH);
|
||||
CU_ASSERT_NOT_EQUAL(guac_rdp_fs_normalize_path(input, normalized), 0);
|
||||
free(input);
|
||||
|
||||
/* Exactly maximum length */
|
||||
input = generate_path(GUAC_RDP_FS_MAX_PATH - 1);
|
||||
input = generate_path(GUAC_RDP_FS_MAX_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