diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2007-04-12 22:38:54 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2007-04-12 22:38:54 +0000 |
commit | 6be615615d538813e3f6dbae46949c1fe9346524 (patch) | |
tree | 2ad7a3837e154a536f9a0c5d37a4a857b29bd61e /uisimulator/common/io.c | |
parent | 6222b2e693ef3c747e2ea815b4ace2e0ef491e3d (diff) | |
download | rockbox-6be615615d538813e3f6dbae46949c1fe9346524.tar.gz rockbox-6be615615d538813e3f6dbae46949c1fe9346524.zip |
Fix sim crashes on long filenames. Patch by Sean Morrisey with some minor changes by me. Fixes FS #6009
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13138 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/common/io.c')
-rw-r--r-- | uisimulator/common/io.c | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index fec9b2611c..c8b3169803 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c | |||
@@ -107,13 +107,13 @@ static unsigned int rockbox2sim(int opt) | |||
107 | 107 | ||
108 | MYDIR *sim_opendir(const char *name) | 108 | MYDIR *sim_opendir(const char *name) |
109 | { | 109 | { |
110 | char buffer[256]; /* sufficiently big */ | 110 | char buffer[MAX_PATH]; /* sufficiently big */ |
111 | DIR *dir; | 111 | DIR *dir; |
112 | 112 | ||
113 | #ifndef __PCTOOL__ | 113 | #ifndef __PCTOOL__ |
114 | if(name[0] == '/') | 114 | if(name[0] == '/') |
115 | { | 115 | { |
116 | sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); | 116 | snprintf(buffer, sizeof(buffer), "%s%s", SIMULATOR_ARCHOS_ROOT, name); |
117 | dir=(DIR *)opendir(buffer); | 117 | dir=(DIR *)opendir(buffer); |
118 | } | 118 | } |
119 | else | 119 | else |
@@ -146,9 +146,9 @@ struct sim_dirent *sim_readdir(MYDIR *dir) | |||
146 | 146 | ||
147 | /* build file name */ | 147 | /* build file name */ |
148 | #ifdef __PCTOOL__ | 148 | #ifdef __PCTOOL__ |
149 | sprintf(buffer, "%s/%s", dir->name, x11->d_name); | 149 | snprintf(buffer, sizeof(buffer), "%s/%s", dir->name, x11->d_name); |
150 | #else | 150 | #else |
151 | sprintf(buffer, SIMULATOR_ARCHOS_ROOT "%s/%s", | 151 | snprintf(buffer, sizeof(buffer), SIMULATOR_ARCHOS_ROOT "%s/%s", |
152 | dir->name, x11->d_name); | 152 | dir->name, x11->d_name); |
153 | #endif | 153 | #endif |
154 | stat(buffer, &s); /* get info */ | 154 | stat(buffer, &s); /* get info */ |
@@ -178,13 +178,13 @@ void sim_closedir(MYDIR *dir) | |||
178 | 178 | ||
179 | int sim_open(const char *name, int o) | 179 | int sim_open(const char *name, int o) |
180 | { | 180 | { |
181 | char buffer[256]; /* sufficiently big */ | 181 | char buffer[MAX_PATH]; /* sufficiently big */ |
182 | int opts = rockbox2sim(o); | 182 | int opts = rockbox2sim(o); |
183 | 183 | ||
184 | #ifndef __PCTOOL__ | 184 | #ifndef __PCTOOL__ |
185 | if(name[0] == '/') | 185 | if(name[0] == '/') |
186 | { | 186 | { |
187 | sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); | 187 | snprintf(buffer, sizeof(buffer), "%s%s", SIMULATOR_ARCHOS_ROOT, name); |
188 | 188 | ||
189 | debugf("We open the real file '%s'\n", buffer); | 189 | debugf("We open the real file '%s'\n", buffer); |
190 | return open(buffer, opts, 0666); | 190 | return open(buffer, opts, 0666); |
@@ -202,16 +202,15 @@ int sim_open(const char *name, int o) | |||
202 | int sim_creat(const char *name) | 202 | int sim_creat(const char *name) |
203 | { | 203 | { |
204 | #ifndef __PCTOOL__ | 204 | #ifndef __PCTOOL__ |
205 | char buffer[256]; /* sufficiently big */ | 205 | char buffer[MAX_PATH]; /* sufficiently big */ |
206 | if(name[0] == '/') | 206 | if(name[0] == '/') |
207 | { | 207 | { |
208 | sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); | 208 | snprintf(buffer, sizeof(buffer), "%s%s", SIMULATOR_ARCHOS_ROOT, name); |
209 | 209 | ||
210 | debugf("We create the real file '%s'\n", buffer); | 210 | debugf("We create the real file '%s'\n", buffer); |
211 | return open(buffer, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666); | 211 | return open(buffer, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666); |
212 | } | 212 | } |
213 | fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", | 213 | fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name); |
214 | name); | ||
215 | return -1; | 214 | return -1; |
216 | #else | 215 | #else |
217 | return open(name, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666); | 216 | return open(name, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666); |
@@ -227,10 +226,10 @@ int sim_mkdir(const char *name) | |||
227 | return mkdir(name, 0777); | 226 | return mkdir(name, 0777); |
228 | # endif | 227 | # endif |
229 | #else | 228 | #else |
230 | char buffer[256]; /* sufficiently big */ | 229 | char buffer[MAX_PATH]; /* sufficiently big */ |
230 | |||
231 | snprintf(buffer, sizeof(buffer), "%s%s", SIMULATOR_ARCHOS_ROOT, name); | ||
231 | 232 | ||
232 | sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); | ||
233 | |||
234 | debugf("We create the real directory '%s'\n", buffer); | 233 | debugf("We create the real directory '%s'\n", buffer); |
235 | #ifdef WIN32 | 234 | #ifdef WIN32 |
236 | /* since we build with -DNOCYGWIN we have the plain win32 version */ | 235 | /* since we build with -DNOCYGWIN we have the plain win32 version */ |
@@ -246,11 +245,11 @@ int sim_rmdir(const char *name) | |||
246 | #ifdef __PCTOOL__ | 245 | #ifdef __PCTOOL__ |
247 | return rmdir(name); | 246 | return rmdir(name); |
248 | #else | 247 | #else |
249 | char buffer[256]; /* sufficiently big */ | 248 | char buffer[MAX_PATH]; /* sufficiently big */ |
250 | if(name[0] == '/') | 249 | if(name[0] == '/') |
251 | { | 250 | { |
252 | sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); | 251 | snprintf(buffer, sizeof(buffer), "%s%s", SIMULATOR_ARCHOS_ROOT, name); |
253 | 252 | ||
254 | debugf("We remove the real directory '%s'\n", buffer); | 253 | debugf("We remove the real directory '%s'\n", buffer); |
255 | return rmdir(buffer); | 254 | return rmdir(buffer); |
256 | } | 255 | } |
@@ -263,14 +262,14 @@ int sim_remove(const char *name) | |||
263 | #ifdef __PCTOOL__ | 262 | #ifdef __PCTOOL__ |
264 | return remove(name); | 263 | return remove(name); |
265 | #else | 264 | #else |
266 | char buffer[256]; /* sufficiently big */ | 265 | char buffer[MAX_PATH]; /* sufficiently big */ |
267 | 266 | ||
268 | #ifdef HAVE_DIRCACHE | 267 | #ifdef HAVE_DIRCACHE |
269 | dircache_remove(name); | 268 | dircache_remove(name); |
270 | #endif | 269 | #endif |
271 | 270 | ||
272 | if(name[0] == '/') { | 271 | if(name[0] == '/') { |
273 | sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); | 272 | snprintf(buffer, sizeof(buffer), "%s%s", SIMULATOR_ARCHOS_ROOT, name); |
274 | 273 | ||
275 | debugf("We remove the real file '%s'\n", buffer); | 274 | debugf("We remove the real file '%s'\n", buffer); |
276 | return remove(buffer); | 275 | return remove(buffer); |
@@ -284,16 +283,18 @@ int sim_rename(const char *oldpath, const char* newpath) | |||
284 | #ifdef __PCTOOL__ | 283 | #ifdef __PCTOOL__ |
285 | return rename(oldpath, newpath); | 284 | return rename(oldpath, newpath); |
286 | #else | 285 | #else |
287 | char buffer1[256]; | 286 | char buffer1[MAX_PATH]; |
288 | char buffer2[256]; | 287 | char buffer2[MAX_PATH]; |
289 | 288 | ||
290 | #ifdef HAVE_DIRCACHE | 289 | #ifdef HAVE_DIRCACHE |
291 | dircache_rename(oldpath, newpath); | 290 | dircache_rename(oldpath, newpath); |
292 | #endif | 291 | #endif |
293 | 292 | ||
294 | if(oldpath[0] == '/') { | 293 | if(oldpath[0] == '/') { |
295 | sprintf(buffer1, "%s%s", SIMULATOR_ARCHOS_ROOT, oldpath); | 294 | snprintf(buffer1, sizeof(buffer1), "%s%s", SIMULATOR_ARCHOS_ROOT, |
296 | sprintf(buffer2, "%s%s", SIMULATOR_ARCHOS_ROOT, newpath); | 295 | oldpath); |
296 | snprintf(buffer2, sizeof(buffer2), "%s%s", SIMULATOR_ARCHOS_ROOT, | ||
297 | newpath); | ||
297 | 298 | ||
298 | debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2); | 299 | debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2); |
299 | return rename(buffer1, buffer2); | 300 | return rename(buffer1, buffer2); |
@@ -384,7 +385,7 @@ void *sim_codec_load_ram(char* codecptr, int size, | |||
384 | int copy_n; | 385 | int copy_n; |
385 | int codec_count; | 386 | int codec_count; |
386 | #ifdef WIN32 | 387 | #ifdef WIN32 |
387 | char buf[256]; | 388 | char buf[MAX_PATH]; |
388 | #endif | 389 | #endif |
389 | 390 | ||
390 | *pd = NULL; | 391 | *pd = NULL; |
@@ -395,7 +396,7 @@ void *sim_codec_load_ram(char* codecptr, int size, | |||
395 | to find an unused filename */ | 396 | to find an unused filename */ |
396 | for (codec_count = 0; codec_count < 10; codec_count++) | 397 | for (codec_count = 0; codec_count < 10; codec_count++) |
397 | { | 398 | { |
398 | sprintf(path, TEMP_CODEC_FILE, codec_count); | 399 | snprintf(path, sizeof(path), TEMP_CODEC_FILE, codec_count); |
399 | 400 | ||
400 | fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU); | 401 | fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU); |
401 | if (fd >= 0) | 402 | if (fd >= 0) |
@@ -453,13 +454,13 @@ void sim_codec_close(void *pd) | |||
453 | void *sim_plugin_load(char *plugin, void **pd) | 454 | void *sim_plugin_load(char *plugin, void **pd) |
454 | { | 455 | { |
455 | void *hdr; | 456 | void *hdr; |
456 | char path[256]; | 457 | char path[MAX_PATH]; |
457 | #ifdef WIN32 | 458 | #ifdef WIN32 |
458 | char buf[256]; | 459 | char buf[MAX_PATH]; |
459 | #endif | 460 | #endif |
460 | 461 | ||
461 | snprintf(path, sizeof path, "archos%s", plugin); | 462 | snprintf(path, sizeof(path), "archos%s", plugin); |
462 | 463 | ||
463 | *pd = NULL; | 464 | *pd = NULL; |
464 | 465 | ||
465 | *pd = dlopen(path, RTLD_NOW); | 466 | *pd = dlopen(path, RTLD_NOW); |
@@ -467,7 +468,7 @@ void *sim_plugin_load(char *plugin, void **pd) | |||
467 | DEBUGF("failed to load %s\n", plugin); | 468 | DEBUGF("failed to load %s\n", plugin); |
468 | #ifdef WIN32 | 469 | #ifdef WIN32 |
469 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, | 470 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, |
470 | buf, sizeof buf, NULL); | 471 | buf, sizeof(buf), NULL); |
471 | DEBUGF("dlopen(%s): %s\n", path, buf); | 472 | DEBUGF("dlopen(%s): %s\n", path, buf); |
472 | #else | 473 | #else |
473 | DEBUGF("dlopen(%s): %s\n", path, dlerror()); | 474 | DEBUGF("dlopen(%s): %s\n", path, dlerror()); |