diff options
author | Richard Jones <rjones@redhat.com> | 2010-01-22 11:01:06 +0000 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2010-01-25 12:07:34 +0000 |
commit | 58abe782bf7137526b4a5c7e6d5d2b145e3b09d2 (patch) | |
tree | 7a58d84c5e3ae7362c386611e2b65047d31d2952 /fish | |
parent | 306077ac965cde0a5605782921d33a72bb77c382 (diff) | |
download | libguestfs-58abe782bf7137526b4a5c7e6d5d2b145e3b09d2.tar.gz libguestfs-58abe782bf7137526b4a5c7e6d5d2b145e3b09d2.tar.xz libguestfs-58abe782bf7137526b4a5c7e6d5d2b145e3b09d2.zip |
guestfish: Use xstrtol to parse integers (RHBZ#557655).
Current code uses atoi to parse the generator Int type and
atoll to parse the generator Int64 type. The problem with the
ato* functions is that they don't cope with errors very well,
and they cannot parse numbers that begin with 0.. or 0x..
for octal and hexadecimal respectively.
This replaces the atoi call with a call to Gnulib xstrtol
and the atoll call with a call to Gnulib xstrtoll.
The generated code looks like this for all Int arguments:
{
strtol_error xerr;
long r;
xerr = xstrtol (argv[0], NULL, 0, &r, "");
if (xerr != LONGINT_OK) {
fprintf (stderr,
_("%s: %s: invalid integer parameter (%s returned %d)\n"),
cmd, "memsize", "xstrtol", xerr);
return -1;
}
/* The Int type in the generator is a signed 31 bit int. */
if (r < (-(2LL<<30)) || r > ((2LL<<30)-1)) {
fprintf (stderr, _("%s: %s: integer out of range\n"), cmd, "memsize");
return -1;
}
/* The check above should ensure this assignment does not overflow. */
memsize = r;
}
and like this for all Int64 arguments (note we don't need the
range check for these):
{
strtol_error xerr;
long long r;
xerr = xstrtoll (argv[1], NULL, 0, &r, "");
if (xerr != LONGINT_OK) {
fprintf (stderr,
_("%s: %s: invalid integer parameter (%s returned %d)\n"),
cmd, "size", "xstrtoll", xerr);
return -1;
}
size = r;
}
Note this also fixes an unrelated bug in guestfish handling of
RBufferOut. We were using 'fwrite' without checking the return
value, and this could have caused silent failures, eg. in the case
where there was not enough disk space to store the resulting file,
or even if the program was interrupted (but continued) during the
write.
Replace this with Gnulib 'full-write', and check the return value
and report errors.
Diffstat (limited to 'fish')
-rw-r--r-- | fish/guestfish.pod | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/fish/guestfish.pod b/fish/guestfish.pod index 13a9fa7d..13645456 100644 --- a/fish/guestfish.pod +++ b/fish/guestfish.pod @@ -296,6 +296,25 @@ must be escaped with a backslash. command "/bin/echo 'foo bar'" command "/bin/echo \'foo\'" +=head1 NUMBERS + +Commands which take integers as parameters use the C convention which +is to use C<0> to prefix an octal number or C<0x> to prefix a +hexadecimal number. For example: + + 1234 decimal number 1234 + 02322 octal number, equivalent to decimal 1234 + 0x4d2 hexadecimal number, equivalent to decimal 1234 + +When using the C<chmod> command, you almost always want to specify an +octal number for the mode, and you must prefix it with C<0> (unlike +the Unix L<chmod(1)> program): + + chmod 0777 /public # OK + chmod 777 /public # WRONG! This is mode 777 decimal = 01411 octal. + +Commands that return numbers currently always print them in decimal. + =head1 WILDCARDS AND GLOBBING Neither guestfish nor the underlying guestfs API performs |