* updated libkomparediff2 (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / package / base / embutils / mount.patch
blob7eb5430ece64b39ebff2529126a879221d56bf23
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../embutils/mount.patch
5 # Copyright (C) 2004 - 2018 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 Hardened mount to not crash when the directory was not found in /etc/fstab and
18 improved the tokenizing to strip white spaces, since the files are often
19 indented in tabular form and fixed the entry parsing to not overwrite memory.
21 - Rene Rebe <rene@exactcode.de>
23 --- embutils-0.19/mount.c 2006-11-05 20:10:18.000000000 +0000
24 +++ embutils-0.19-fixed/mount.c 2007-08-25 09:20:23.000000000 +0000
25 @@ -148,6 +148,11 @@
26 char* tmp;
27 if(s)
28 buffer=s;
30 + /* skip leading spaces */
31 + while(*buffer && isspace(*buffer))
32 + ++buffer;
34 tmp=buffer;
35 for(;*buffer;++buffer) {
36 if(isspace(*buffer)) {
37 @@ -182,9 +187,10 @@
38 if(buffer[0]=='#')
39 continue;
40 i=0;
41 - entries[i]=spacetok(buffer);
42 - while((entries[++i]=spacetok(NULL)) &&
43 - i<sizeof(entries));
44 + entries[i++]=spacetok(buffer);
46 + while((entries[i++]=spacetok(NULL)) &&
47 + i<(sizeof(entries)/sizeof(char*)));
48 break;
51 @@ -463,13 +470,18 @@
52 if(fh) {
53 struct mntentry *mnt;
54 while((mnt=mnt_entry(fh)))
55 - if(!strcmp(mnt->dir,device)) {
56 + if(mnt->dir && !strcmp(mnt->dir,device)) {
57 device=mnt->device;
58 dir=mnt->dir;
59 fs_type=mnt->fs_type;
60 parse_options(mnt->opts,&flags,data+data_size,DATA_BUFFER_SIZE-data_size);
61 break;
63 + if (!dir) {
64 + __write2(device);
65 + write(2," no found in /etc/fstab\n",24);
66 + return 1;
67 + }
69 #ifdef CLEANUP
70 io_close(fh);
72 Added bind mount and fixed the option_parser to be able to parse options
73 with only one part and no , seperator ...
75 Rene Rebe <rene@exactcode.de>
77 --- embutils-0.17/mount.c 2004-01-09 17:03:48.000000000 +0100
78 +++ embutils-0.17-mount/mount.c 2005-06-19 15:13:34.000000000 +0200
79 @@ -26,6 +26,7 @@
80 #ifdef LINUX
81 #include <sys/mount.h>
82 #include <paths.h>
83 +#include <linux/fs.h> /* MS_MOVE */
84 #ifdef _PATH_MOUNTED
85 const char *const mtab=_PATH_MOUNTED;
86 #else
87 @@ -227,6 +228,9 @@
88 {"suid", ~MS_NOSUID, 0},
89 {"sync", ~0, MS_SYNCHRONOUS},
90 {"bind", ~0, MS_BIND},
91 +#ifdef LINUX
92 + {"move", ~0, MS_MOVE},
93 +#endif
94 {0, 0, 0}
97 @@ -240,10 +244,15 @@
98 size_t data_set=0;
99 for(;;) {
100 const struct mount_options *i;
101 - char *ptr=strchr(str,',');
102 - if(!ptr)
103 + char *ptr;
105 + if (!str || !*str)
106 break;
107 - *ptr=0;
109 + ptr=strchr(str,',');
110 + if(!ptr) ptr=(char*)str+strlen(str)-1;
111 + else *ptr=0;
113 for(i=options; i->name; ++i)
114 if(!strcmp(str,i->name)) {
115 *flags&=i->and;
117 Do not segfault by default when no type was give, also none might be needed
118 due bind or move mounts.
120 - Rene Rebe <rene@exactcode.de>
122 --- embutils-0.17/mount.c 2005-12-18 23:49:12.000000000 +0100
123 +++ embutils-0.17-patched/mount.c 2005-12-19 10:02:38.000000000 +0100
124 @@ -414,7 +414,7 @@
126 int main(int argc, char **argv) {
127 unsigned long flags=0;
128 - const char *fs_type=NULL;
129 + const char *fs_type="";
130 const char *device=NULL;
131 const char *dir=NULL;
132 enum { DATA_BUFFER_SIZE=100 };
134 The option code was relying on accidently zero initialization, although
135 the code even had explicit zeroing later on. Depending on compiler,
136 optimization and architecture coudl pass random data to the kernel, and
137 also failed to parse more than one option.
139 - Rene Rebe <rene@exactcode.de>
141 --- ./mount.c.vanilla 2016-06-25 03:10:40.130000362 +0000
142 +++ ./mount.c 2018-08-21 10:55:29.969876048 +0000
143 @@ -267,12 +268,12 @@
144 break;
146 if(!i->name) { /*no options was found*/
147 - size_t option_length=strlen(str)+1;
148 + size_t option_length=strlen(str);
149 if(data_set) {
150 *(data+data_set)=',';
151 ++data_set;
153 - memcpy(data+data_set,str,option_length);
154 + memcpy(data+data_set,str,option_length+1);/*incl 0*/
155 data_set+=option_length;
156 if(data_set>=data_size)
157 return; /*too many options*/
158 @@ -419,6 +418,7 @@
159 const char *dir=NULL;
160 enum { DATA_BUFFER_SIZE=100 };
161 char data[DATA_BUFFER_SIZE];
162 + *data = 0;
163 size_t data_size=0;
164 bool write_mtab=true;
165 bool all=false;
166 @@ -466,9 +467,6 @@
170 - if(!data_size)
171 - memset(data,0,DATA_BUFFER_SIZE);
173 if(!all && !device)
174 show_mounts(fs_type);
175 else if(all)