source: rtems/cpukit/libcsupport/src/__usrenv.c @ e22af78

4.115
Last change on this file since e22af78 was 22cd282, checked in by Sebastian Huber <sebastian.huber@…>, on 10/08/14 at 09:24:36

IMFS: Avoid NULL pointer access

Avoid NULL pointer access in IMFS_is_imfs_instance(). File systems
mounted via mount() always have a valid type string.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS File System Location Support
5 *  @ingroup LibIOInternal
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2008.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  Modifications to support reference counting in the file system are
13 *  Copyright (c) 2012 embedded brains GmbH.
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.org/license/LICENSE.
18 */
19
20#if HAVE_CONFIG_H
21  #include "config.h"
22#endif
23
24#include <sys/stat.h>
25
26#include <rtems/libio_.h>
27
28static int null_handler_open(
29  rtems_libio_t *iop,
30  const char *path,
31  int oflag,
32  mode_t mode
33)
34{
35  return -1;
36}
37
38static int null_handler_fstat(
39  const rtems_filesystem_location_info_t *pathloc,
40  struct stat *buf
41)
42{
43  return -1;
44}
45
46const rtems_filesystem_file_handlers_r rtems_filesystem_null_handlers = {
47  .open_h = null_handler_open,
48  .close_h = rtems_filesystem_default_close,
49  .read_h = rtems_filesystem_default_read,
50  .write_h = rtems_filesystem_default_write,
51  .ioctl_h = rtems_filesystem_default_ioctl,
52  .lseek_h = rtems_filesystem_default_lseek,
53  .fstat_h = null_handler_fstat,
54  .ftruncate_h = rtems_filesystem_default_ftruncate,
55  .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
56  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
57  .fcntl_h = rtems_filesystem_default_fcntl,
58  .kqfilter_h = rtems_filesystem_default_kqfilter,
59  .poll_h = rtems_filesystem_default_poll,
60  .readv_h = rtems_filesystem_default_readv,
61  .writev_h = rtems_filesystem_default_writev
62};
63
64static void null_op_lock_or_unlock(
65  const rtems_filesystem_mount_table_entry_t *mt_entry
66)
67{
68  /* Do nothing */
69}
70
71static int null_op_mknod(
72  const rtems_filesystem_location_info_t *parentloc,
73  const char *name,
74  size_t namelen,
75  mode_t mode,
76  dev_t dev
77)
78{
79  return -1;
80}
81
82static int null_op_rmnod(
83  const rtems_filesystem_location_info_t *parentloc,
84  const rtems_filesystem_location_info_t *loc
85)
86{
87  return -1;
88}
89
90static int null_op_link(
91  const rtems_filesystem_location_info_t *parentloc,
92  const rtems_filesystem_location_info_t *targetloc,
93  const char *name,
94  size_t namelen
95)
96{
97  return -1;
98}
99
100static int null_op_fchmod(
101  const rtems_filesystem_location_info_t *pathloc,
102  mode_t mode
103)
104{
105  return -1;
106}
107
108static int null_op_chown(
109  const rtems_filesystem_location_info_t *loc,
110  uid_t owner,
111  gid_t group
112)
113{
114  return -1;
115}
116
117static int null_op_clonenode(
118  rtems_filesystem_location_info_t *loc
119)
120{
121  return -1;
122}
123
124static int null_op_mount(
125  rtems_filesystem_mount_table_entry_t *mt_entry
126)
127{
128  return -1;
129}
130
131static int null_op_fsmount_me(
132  rtems_filesystem_mount_table_entry_t *mt_entry,
133  const void *data
134)
135{
136  return -1;
137}
138
139static int null_op_unmount(
140  rtems_filesystem_mount_table_entry_t *mt_entry
141)
142{
143  return -1;
144}
145
146static void null_op_fsunmount_me(
147  rtems_filesystem_mount_table_entry_t *mt_entry
148)
149{
150  /* Do nothing */
151}
152
153static int null_op_utime(
154  const rtems_filesystem_location_info_t *loc,
155  time_t actime,
156  time_t modtime
157)
158{
159  return -1;
160}
161
162static int null_op_symlink(
163  const rtems_filesystem_location_info_t *parentloc,
164  const char *name,
165  size_t namelen,
166  const char *target
167)
168{
169  return -1;
170}
171
172static ssize_t null_op_readlink(
173  const rtems_filesystem_location_info_t *loc,
174  char *buf,
175  size_t bufsize
176)
177{
178  return -1;
179}
180
181static int null_op_rename(
182  const rtems_filesystem_location_info_t *oldparentloc,
183  const rtems_filesystem_location_info_t *oldloc,
184  const rtems_filesystem_location_info_t *newparentloc,
185  const char *name,
186  size_t namelen
187)
188{
189  return -1;
190}
191
192static int null_op_statvfs(
193  const rtems_filesystem_location_info_t *__restrict loc,
194  struct statvfs *__restrict buf
195)
196{
197  return -1;
198}
199
200static const rtems_filesystem_operations_table null_ops = {
201  .lock_h = null_op_lock_or_unlock,
202  .unlock_h = null_op_lock_or_unlock,
203  .eval_path_h = rtems_filesystem_default_eval_path,
204  .link_h = null_op_link,
205  .are_nodes_equal_h = rtems_filesystem_default_are_nodes_equal,
206  .node_type_h = rtems_filesystem_default_node_type,
207  .mknod_h = null_op_mknod,
208  .rmnod_h = null_op_rmnod,
209  .fchmod_h = null_op_fchmod,
210  .chown_h = null_op_chown,
211  .clonenod_h = null_op_clonenode,
212  .freenod_h = rtems_filesystem_default_freenode,
213  .mount_h = null_op_mount,
214  .fsmount_me_h = null_op_fsmount_me,
215  .unmount_h = null_op_unmount,
216  .fsunmount_me_h = null_op_fsunmount_me,
217  .utime_h = null_op_utime,
218  .symlink_h = null_op_symlink,
219  .readlink_h = null_op_readlink,
220  .rename_h = null_op_rename,
221  .statvfs_h = null_op_statvfs
222};
223
224rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry = {
225  .location_chain = RTEMS_CHAIN_INITIALIZER_ONE_NODE(
226    &rtems_filesystem_global_location_null.location.mt_entry_node
227  ),
228  .ops = &null_ops,
229  .mt_point_node = &rtems_filesystem_global_location_null,
230  .mt_fs_root = &rtems_filesystem_global_location_null,
231  .mounted = false,
232  .writeable = false,
233  .type = ""
234};
235
236rtems_filesystem_global_location_t rtems_filesystem_global_location_null = {
237  .location = {
238    .mt_entry_node = RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN(
239      &rtems_filesystem_null_mt_entry.location_chain
240    ),
241    .handlers = &rtems_filesystem_null_handlers,
242    .mt_entry = &rtems_filesystem_null_mt_entry
243  },
244
245  /*
246   * The initial reference count accounts for the following references
247   *  o the root directory of the user environment,
248   *  o the current directory of the user environment,
249   *  o the root node of the null file system instance, and
250   *  o the mount point node of the null file system instance.
251   */
252  .reference_count = 4
253};
254
255rtems_user_env_t rtems_global_user_env = {
256  .current_directory = &rtems_filesystem_global_location_null,
257  .root_directory = &rtems_filesystem_global_location_null,
258  .umask = S_IWGRP | S_IWOTH
259};
260
261pthread_key_t rtems_current_user_env_key;
Note: See TracBrowser for help on using the repository browser.