Hello Ahmed,

Thanks for the update. Could you send the revised diff to the list? I’d
like to check where size > UINT_MAX is
evaluated relative to suffix handling and the cast to off_t. What sets
UINT_MAX as the upper bound on the size in bytes?

One case worth checking is a runtime update that supplies only --mode. With
--size omitted, parse_opt_size()
 never runs, so its checks cannot preserve the existing page limit. Does
the revised ARGP_KEY_SUCCESS leave tmpfs_page_limit
unchanged in that case? I’d leave the intended meaning of an explicit
--size=0 for Samuel to confirm.

Best regards,
Alperen Erkan

On Tue, Nov 24, 2026 at 1:42 PM Ahmed Khider <[email protected]> wrote:

> Hello Alperen
>
> * I had fixed it *
>
> *the size now is *
> *-if (size > UINT_MAX)*
>
> *- I removed *end != '\0'*
>
> *- I set it to *end !='\0'*
>
> *I am waiting to hear what Samuel thinks about values->mode = (mode_t) -
> 1.  And the  tmpfs_page_limit = 0. *
>
>
> *I know it gives unlimited memory, but I didn't know if that can happen.*
>
> *Though parse_opt_size checks only for size > UINT_MAX *
> * and size < 0 only *
>
>
>
>
>
> On Tue, Nov 24, 2026 at 11:48 AM Alperen Erkan <[email protected]>
> wrote:
>
>> Hello Ahmed,
>>
>> I see three issues in parse_opt_size() and parse_opt():
>> - if (size > 0) rejects ordinary positive sizes. For example, --size=4096
>> reaches “size too large”.
>> Please check the range before casting to off_t.
>>
>> - The new *end != '\0' check in parse_opt_size() rejects suffixes before
>> the existing suffix parser
>> can handle them. At that point, check errno and end == arg, then let the
>> suffix parser validate the
>> remainder.
>>
>> - The mode check is reversed. *end == '\0' rejects --mode=0755, while
>> --mode=0755x passes that
>> check. It should be *end != '\0'.
>> For runtime updates, could you also guard the two assignments in
>> ARGP_KEY_SUCCESS independently?
>> A mode-only update should preserve the page limit, and a size-only update
>> should preserve the mode.
>> Once the size has been validated, size / vm_page_size + (size %
>> vm_page_size != 0) rounds up without
>> risking overflow in the addition before division.
>>
>> Best regards,
>> Alperen Erkan
>>
>> On Tue, Nov 24, 2026 at 11:29 AM Ahmed Khider <[email protected]>
>> wrote:
>>
>>> ---
>>>  tmpfs/tmpfs.c | 14 ++++++++------
>>>  1 file changed, 8 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/tmpfs/tmpfs.c b/tmpfs/tmpfs.c
>>> index ad5e298..af8aedf 100644
>>> --- a/tmpfs/tmpfs.c
>>> +++ b/tmpfs/tmpfs.c
>>> @@ -118,9 +118,10 @@ struct option_values
>>>  static error_t
>>>  parse_opt_size (const char *arg, struct argp_state *state, off_t
>>> *newsize)
>>>  {
>>> +  errno = 0;
>>>    char *end = NULL;
>>>    intmax_t size = strtoimax (arg, &end, 0);
>>> -  if (end == NULL || end == arg)
>>> +  if (errno != 0 || *end != '\0' || end == arg)
>>>      {
>>>        argp_error (state, "argument must be a number");
>>>        return EINVAL;
>>> @@ -163,7 +164,7 @@ parse_opt_size (const char *arg, struct argp_state
>>> *state, off_t *newsize)
>>>         }
>>>      }
>>>    size = (off_t) size;
>>> -  if (size < 0)
>>> +  if (size > 0)
>>>      {
>>>        argp_error (state, "size too large");
>>>        return EINVAL;
>>> @@ -200,9 +201,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 +259,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 +421,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 +431,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
>>>
>>>
>>>

Reply via email to