Skip to content

Commit

Permalink
Merge branch '4598_tar_segfault'
Browse files Browse the repository at this point in the history
* 4598_tar_segfault:
  tar: initialize variables passed to stoint().
  (decode_num): simplify expression.
  Ticket #4598: fix segfault on open TAR archive.

Signed-off-by: Yury V. Zaytsev <[email protected]>
  • Loading branch information
aborodin authored and zyv committed Oct 11, 2024
2 parents b294d65 + 0c505b9 commit 54a4c7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/vfs/tar/tar-sparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ static struct tar_sparse_optab const pax_optab = {
static gboolean
decode_num (uintmax_t *num, const char *arg, uintmax_t maxval)
{
char *arg_lim;
gboolean overflow;
char *arg_lim = NULL;
gboolean overflow = FALSE;

*num = stoint (arg, &arg_lim, &overflow, 0, maxval);
return (((arg_lim == arg ? 1 : 0) | (*arg_lim != '\0') | (overflow ? 1 : 0)) == 0);
return !(arg_lim == arg || *arg_lim != '\0' || overflow);
}

/* --------------------------------------------------------------------------------------------- */
Expand Down
15 changes: 8 additions & 7 deletions src/vfs/tar/tar-xheader.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,13 @@ static struct timespec
decode_timespec (const char *arg, char **arg_lim, gboolean parse_fraction)
{
int ns = -1;
gboolean overflow;
gboolean overflow = FALSE;
time_t s;
char const *p = *arg_lim;
char const *p;
struct timespec r;

s = stoint (arg, arg_lim, &overflow, TYPE_MINIMUM (time_t), TYPE_MAXIMUM (time_t));
p = *arg_lim;

if (p != arg)
{
Expand Down Expand Up @@ -340,8 +341,8 @@ static gboolean
decode_signed_num (intmax_t *num, const char *arg, intmax_t minval, uintmax_t maxval,
const char *keyword)
{
char *arg_lim;
gboolean overflow;
char *arg_lim = NULL;
gboolean overflow = FALSE;
intmax_t u;

(void) keyword;
Expand Down Expand Up @@ -582,7 +583,7 @@ decode_record (struct xheader *xhdr, char **ptr,
char *start = *ptr;
char *p = start;
idx_t len;
char *len_lim;
char *len_lim = NULL;
const char *keyword;
char *nextp;
idx_t len_max;
Expand Down Expand Up @@ -801,8 +802,8 @@ sparse_map_decoder (struct tar_stat_info *st, const char *keyword, const char *a
while (TRUE)
{
off_t u;
char *delim;
gboolean overflow;
char *delim = NULL;
gboolean overflow = FALSE;

u = stoint (arg, &delim, &overflow, 0, TYPE_MAXIMUM (off_t));

Expand Down

0 comments on commit 54a4c7d

Please sign in to comment.