summaryrefslogtreecommitdiff
path: root/core
authorerik <erik>2007-01-26 21:43:58 (UTC)
committer erik <erik>2007-01-26 21:43:58 (UTC)
commit3cd37427b5c5f26f62cff583fbde914467ddafe3 (patch) (unidiff)
tree664a2c1cf2198b69f94e9aa683133a3d92c98511 /core
parentf77da1ae08512b02a3c50a124f823ed77e53dd64 (diff)
downloadopie-3cd37427b5c5f26f62cff583fbde914467ddafe3.zip
opie-3cd37427b5c5f26f62cff583fbde914467ddafe3.tar.gz
opie-3cd37427b5c5f26f62cff583fbde914467ddafe3.tar.bz2
Both files in this commit exhibit the wrong way to use temporary files.
For TEHistory.cpp, it uses tmpfile() which produces a file which has a name that can be guessed. For vmemo.cpp, it uses tmpname() which only creates a predictable string. Both uses have been switched to using mkstemp() wrapped around umask(). This produces a much less predictable file that also has guaranteed restrictive permissions. I went a little farther in vmemo because it calls out to the shell using system to 'mv' the new file. That is kinda wasteful so I switched it to use rename instead.
Diffstat (limited to 'core') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp73
1 files changed, 48 insertions, 25 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index 8ba1eb7..1a8f154 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -329,12 +329,32 @@ bool VMemo::startRecording() {
329 msgLabel->show(); 329 msgLabel->show();
330 } 330 }
331 331
332// open tmp file here 332 // open tmp file here
333 char *pointer; 333 char *tmpFilePath = 0;
334 pointer=tmpnam(NULL); 334 char *tmpDir = getenv("TMPDIR");
335 odebug << "Opening tmp file " << pointer << "" << oendl; 335 if (tmpDir && *tmpDir != '\0') {
336 tmpFilePath = new char[strlen(tmpDir) + strlen("/vmemo-wav-XXXXXX") + 1];
337 strcpy(tmpFilePath, tmpDir);
338 free(tmpDir);
339 } else {
340 tmpFilePath = new char[strlen("/tmp/vmemo-wav-XXXXXX") + 1];
341 strcpy(tmpFilePath, "/tmp");
342 }
343 strcat(tmpFilePath, "/vmemo-wav-XXXXXX");
344 mode_t currUmask = umask(S_IRWXO | S_IRWXG);
345 int tmpFd = mkstemp(tmpFilePath);
346 umask(currUmask);
347 if (tmpFd == -1) {
348 owarn << "Could not open temp file with template " << tmpFilePath
349 << oendl;
350 delete [] tmpFilePath;
351 return false;
352 } else
353 odebug << "Opened temp file " << tmpFilePath << "" << oendl;
354
355 close(tmpFd);
336 356
337 if(openWAV(pointer ) == -1) { 357 if(openWAV(tmpFilePath ) == -1) {
338 358
339 QString err("Could not open the temp file\n"); 359 QString err("Could not open the temp file\n");
340 err += fileName; 360 err += fileName;
@@ -344,27 +364,30 @@ bool VMemo::startRecording() {
344 } 364 }
345 if( record() ) { 365 if( record() ) {
346 366
347 QString cmd; 367 if( fileName.find(".wav",0,true) == -1)
348 if( fileName.find(".wav",0,true) == -1) 368 fileName += ".wav";
349 fileName += ".wav";
350 369
351 cmd.sprintf("mv %s "+fileName, pointer); 370 int retVal = rename(tmpFilePath, fileName.local8Bit());
352// move tmp file to regular file here 371 if (retVal == -1) {
353 372 owarn << "Could not move " << tmpFilePath << " to " << fileName
354 system(cmd.latin1()); 373 << oendl;
355 374 delete [] tmpFilePath;
356 QArray<int> cats(1); 375 return false;
357 cats[0] = config.readNumEntry("Category", 0); 376 }
358 377 delete [] tmpFilePath;
359 QString dlName("vm_"); 378
360 dlName += date; 379 QArray<int> cats(1);
361 DocLnk l; 380 cats[0] = config.readNumEntry("Category", 0);
362 l.setFile(fileName); 381
363 l.setName(dlName); 382 QString dlName("vm_");
364 l.setType("audio/x-wav"); 383 dlName += date;
365 l.setCategories(cats); 384 DocLnk l;
366 l.writeLink(); 385 l.setFile(fileName);
367 return true; 386 l.setName(dlName);
387 l.setType("audio/x-wav");
388 l.setCategories(cats);
389 l.writeLink();
390 return true;
368 } else 391 } else
369 return false; 392 return false;
370 393