---
tmpfs/tmpfs.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/tmpfs/tmpfs.c b/tmpfs/tmpfs.c
index ad5e298..fa4c37a 100644
--- a/tmpfs/tmpfs.c
+++ b/tmpfs/tmpfs.c
@@ -55,6 +55,7 @@ struct node *diskfs_root_node;
mach_port_t default_pager;
off_t tmpfs_page_limit, tmpfs_space_used;
+off_t tmpfs_size_limit = UINT_MAX;
mode_t tmpfs_root_mode = -1;
error_t
@@ -125,6 +126,11 @@ parse_opt_size (const char *arg, struct argp_state *state,
off_t *newsize)
argp_error (state, "argument must be a number");
return EINVAL;
}
+ if (size == 0)
+ {
+ argp_error (state, "argument must be bigger than zero");
+ return EINVAL;
+ }
if (size < 0)
{
argp_error (state, "negative size not meaningful");
@@ -163,12 +169,13 @@ parse_opt_size (const char *arg, struct argp_state
*state, off_t *newsize)
}
}
size = (off_t) size;
- if (size < 0)
+ if (size > tmpfs_size_limit )
{
argp_error (state, "size too large");
return EINVAL;
}
+
*newsize = size;
return 0;
@@ -191,7 +198,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
return ENOMEM;
state->hook = values;
values->size = -1;
- values->mode = -1;
+ values->mode = (mode_t) -1;
break;
case ARGP_KEY_FINI:
free (values);
@@ -200,9 +207,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
case 'm': /* --mode=OCTAL */
{
+ errno = 0;
char *end = NULL;
mode_t mode = strtoul (arg, &end, 8);
- if (end == NULL || end == arg)
+ if (errno = 0 || *end != '\0' || end == arg)
{
argp_error (state, "argument must be an octal number");
return EINVAL;
@@ -257,7 +265,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
case ARGP_KEY_SUCCESS:
/* All options parse successfully, so implement ours if possible. */
- tmpfs_page_limit = values->size / vm_page_size;
+ tmpfs_page_limit = (values->size + vm_page_size - 1) / vm_page_size;
tmpfs_root_mode = values->mode;
break;
@@ -419,7 +427,7 @@ main (int argc, char **argv)
if (err)
{
error (0, err, "cannot stat underlying node");
- if (tmpfs_root_mode == -1)
+ if (tmpfs_root_mode == (mode_t) -1)
diskfs_root_node->dn_stat.st_mode |= 0777 | S_ISVTX;
else
diskfs_root_node->dn_stat.st_mode |= tmpfs_root_mode;
@@ -429,7 +437,7 @@ main (int argc, char **argv)
}
else
{
- if (tmpfs_root_mode == -1)
+ if (tmpfs_root_mode == (mode_t) -1)
{
diskfs_root_node->dn_stat.st_mode |= st.st_mode &~ S_IFMT;
if (S_ISREG (st.st_mode) && (st.st_mode & 0111) == 0)
--
2.47.3