Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit 54a4c7d

Browse files
aborodinzyv
authored andcommitted
Merge branch '4598_tar_segfault'
* 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 <yury@shurup.com>
2 parents b294d65 + 0c505b9 commit 54a4c7d

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/vfs/tar/tar-sparse.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ static struct tar_sparse_optab const pax_optab = {
253253
static gboolean
254254
decode_num (uintmax_t *num, const char *arg, uintmax_t maxval)
255255
{
256-
char *arg_lim;
257-
gboolean overflow;
256+
char *arg_lim = NULL;
257+
gboolean overflow = FALSE;
258258

259259
*num = stoint (arg, &arg_lim, &overflow, 0, maxval);
260-
return (((arg_lim == arg ? 1 : 0) | (*arg_lim != '\0') | (overflow ? 1 : 0)) == 0);
260+
return !(arg_lim == arg || *arg_lim != '\0' || overflow);
261261
}
262262

263263
/* --------------------------------------------------------------------------------------------- */

src/vfs/tar/tar-xheader.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,13 @@ static struct timespec
255255
decode_timespec (const char *arg, char **arg_lim, gboolean parse_fraction)
256256
{
257257
int ns = -1;
258-
gboolean overflow;
258+
gboolean overflow = FALSE;
259259
time_t s;
260-
char const *p = *arg_lim;
260+
char const *p;
261261
struct timespec r;
262262

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

265266
if (p != arg)
266267
{
@@ -340,8 +341,8 @@ static gboolean
340341
decode_signed_num (intmax_t *num, const char *arg, intmax_t minval, uintmax_t maxval,
341342
const char *keyword)
342343
{
343-
char *arg_lim;
344-
gboolean overflow;
344+
char *arg_lim = NULL;
345+
gboolean overflow = FALSE;
345346
intmax_t u;
346347

347348
(void) keyword;
@@ -582,7 +583,7 @@ decode_record (struct xheader *xhdr, char **ptr,
582583
char *start = *ptr;
583584
char *p = start;
584585
idx_t len;
585-
char *len_lim;
586+
char *len_lim = NULL;
586587
const char *keyword;
587588
char *nextp;
588589
idx_t len_max;
@@ -801,8 +802,8 @@ sparse_map_decoder (struct tar_stat_info *st, const char *keyword, const char *a
801802
while (TRUE)
802803
{
803804
off_t u;
804-
char *delim;
805-
gboolean overflow;
805+
char *delim = NULL;
806+
gboolean overflow = FALSE;
806807

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

0 commit comments

Comments
 (0)