1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

libast: robustness fixes for temporary files and streams

From an OpenSUSE patch:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-pathtemp.dif

See src/lib/libast/man/path.3 for pathtemp()
and src/lib/libast/man/sfio.3 for sftmp()

src/lib/libast/path/pathtemp.c:
- Error check fix: add an access check wrapper function that checks
  if a path was given and if there is enough free space on the
  device, setting errno appropriately in case of trouble.

src/lib/libast/sfio/sftmp.c:
- On Linux, use the /dev/shm shared memory objects for the new
  temporary file descriptor -- that is, do not access HD or SSD but
  only the memory based tmpfs of the POSIX SHM.
This commit is contained in:
Martijn Dekker 2021-02-02 14:44:34 +00:00
parent b12be093d7
commit db71b3ad43
2 changed files with 62 additions and 3 deletions

View file

@ -20,6 +20,14 @@
* *
***********************************************************************/
#include "sfhdr.h"
#if _PACKAGE_ast
# if defined(__linux__) && _lib_statfs
# include <sys/statfs.h>
# ifndef TMPFS_MAGIC
# define TMPFS_MAGIC 0x01021994
# endif
# endif
#endif
/* Create a temporary stream for read/write.
** The stream is originally created as a memory-resident stream.
@ -207,7 +215,24 @@ Sfio_t* f;
int fd;
#if _PACKAGE_ast
# if defined(__linux__) && _lib_statfs
/*
* Use the area of POSIX shared memory objects for the new temporary file descriptor
* that is do not access HD or SSD but only the memory based tmpfs of the POSIX SHM
*/
static int doshm;
static char *shm = "/dev/shm";
if (!doshm)
{
struct statfs fs;
if (statfs(shm, &fs) < 0 || fs.f_type != TMPFS_MAGIC || eaccess(shm, W_OK|X_OK))
shm = NiL;
doshm++;
}
if(!(file = pathtemp(NiL,PATH_MAX,shm,"sf",&fd)))
# else
if(!(file = pathtemp(NiL,PATH_MAX,NiL,"sf",&fd)))
# endif
return -1;
_rmtmp(f, file);
free(file);