-
Notifications
You must be signed in to change notification settings - Fork 0
/
pass_ptr_to_empty_array__list_nomessages.c
85 lines (73 loc) · 2.57 KB
/
pass_ptr_to_empty_array__list_nomessages.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_USER_FORBIDDEN_MOUNTS_LENGTH 100
static int
read_forbidden_mounts (char **array,
unsigned int *ptr_length)
{
char *user_forbidden_mounts[] = { "/mnt/cdrom", "/mnt/cdaudio", "/tmp", "/var",
"/dev/shm", "/mnt/sambadir1", "/mnt/sambadir2" };
unsigned int user_forbidden_mounts_length = sizeof (user_forbidden_mounts)
/ sizeof (user_forbidden_mounts[0]);
if (user_forbidden_mounts_length > *ptr_length)
return 1;
for (unsigned int loop_i_mount = 0; loop_i_mount < user_forbidden_mounts_length; loop_i_mount++)
if ((array[loop_i_mount] = strdup (user_forbidden_mounts[loop_i_mount])) == NULL)
return 1;
*ptr_length = user_forbidden_mounts_length;
return 0;
}
static int
read_forbidden_volumes (char **array,
unsigned int *ptr_length)
{
unsigned int length;
char concat[255];
int snprintf_result;
if (read_forbidden_mounts (array, ptr_length) == 0)
{
length = *ptr_length;
for (unsigned int loop_i_volume = 0; loop_i_volume < length; loop_i_volume++)
{
snprintf_result = snprintf (concat, sizeof (concat), "%s%s", array[loop_i_volume], " changed");
free (array[loop_i_volume]);// without this `free` there is a leak
if ((array[loop_i_volume] = strdup (concat)) == NULL)
return 1;
}
return 0;
}
else
{
return 1;
}
}
static void
update_volumes (void)
{
unsigned int user_forbidden_volumes_length = MAX_USER_FORBIDDEN_MOUNTS_LENGTH;
char *user_forbidden_volumes[user_forbidden_volumes_length];
unsigned int *ptr_user_forbidden_volumes_length = &user_forbidden_volumes_length;
if (read_forbidden_volumes (user_forbidden_volumes, ptr_user_forbidden_volumes_length) == 0)
for (unsigned int loop_i_volume = 0; loop_i_volume < user_forbidden_volumes_length;
loop_i_volume++)
free (user_forbidden_volumes[loop_i_volume]);
}
static void
update_mounts (void)
{
unsigned int user_forbidden_mounts_length = MAX_USER_FORBIDDEN_MOUNTS_LENGTH;
char *user_forbidden_mounts[user_forbidden_mounts_length];
unsigned int *ptr_user_forbidden_mounts_length = &user_forbidden_mounts_length;
if (read_forbidden_mounts (user_forbidden_mounts, ptr_user_forbidden_mounts_length) == 0)
for (unsigned int loop_i_mount = 0; loop_i_mount < user_forbidden_mounts_length;
loop_i_mount++)
free (user_forbidden_mounts[loop_i_mount]);
}
int
main (void)
{
update_volumes ();
update_mounts ();
return 0;
}