Re: [PATCH] mount: make the --offset option support hex number

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Le jeudi 25 mars 2010 à 14:35 +0800, Liu Aleaxander a écrit :
> On Thu, Mar 25, 2010 at 2:19 PM, Américo Wang <xiyou.wangcong@xxxxxxxxx> wrote:
> > On Thu, Mar 25, 2010 at 2:16 PM, Liu Aleaxander <aleaxander@xxxxxxxxx> wrote:
> >> On Thu, Mar 25, 2010 at 1:50 PM, Américo Wang <xiyou.wangcong@xxxxxxxxx> wrote:
> [ snip ]
> >>
> >> If so, I don't think so this can handle the case like the following one:
> >> /sbin/losetup -o 0x7e00fdjfkk /dev/loop0 disk.img
> >
> > Why not refer man pages? Everything is clear:
> >
> >       If endptr is not NULL,  strtoul()  stores  the  address  of  the  first
> >       invalid  character  in  *endptr.   If there were no digits at all, str-
> >       toul() stores the original value of nptr in *endptr  (and  returns  0).
> >       In particular, if *nptr is not '\0' but **endptr is '\0' on return, the
> >       entire string is valid.
> 
> Hi,
> Am I miss something, or misunderstood something?
> 
> In fact, I did just by what the man page said:
>       In particular, if *nptr is not '\0' but **endptr is '\0' on return, the
>       entire string is valid.
> 

Here is an example of code which handle invalid data and overflow:

static int
convert_ullong(const char *s, unsigned long long *value)
{
  unsigned long long result;
  char *endptr = NULL;

  if (s == NULL || *s == '\0') {
    return -1;
  }

  errno = 0;
  result = strtoull(s, &endptr, 0);
  if (s == endptr ||
      (endptr != NULL && *endptr != '\0') ||
      ((result == 0 || result == ULLONG_MAX) && errno != 0)) {
    return -1;
  }
  
  if (value != NULL) {
    *value = result;
  }

  return 0;
}

Regards

-- 
Yann Droneaud

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux