Fix some uses of int in list.c
* src/list.c (decode_xform): Last arg is now int, not a void * pointer to that int. All uses changed. (enforce_one_top_level): Don’t assume string length fits in int. (transform_stat_info): Prefer char to int for typeflag. All uses changed. (decode_header): Prefer bool for booleans. All uses changed. (ugswidth): Now idx_t, not int, since in theory it could exceed INT_MAX. All uses changed. (simple_print_header, print_for_mkdir): Don’t assume printf length fits in int, and similarly for length of user or group name. * src/transform.c (transform_name_fp): Last arg is now int, not void *. All uses changed.
This commit is contained in:
@@ -611,8 +611,8 @@ extern idx_t recent_long_name_blocks;
|
|||||||
extern idx_t recent_long_link_blocks;
|
extern idx_t recent_long_link_blocks;
|
||||||
|
|
||||||
void decode_header (union block *header, struct tar_stat_info *stat_info,
|
void decode_header (union block *header, struct tar_stat_info *stat_info,
|
||||||
enum archive_format *format_pointer, int do_user_group);
|
enum archive_format *format_pointer, bool do_user_group);
|
||||||
void transform_stat_info (int typeflag, struct tar_stat_info *stat_info);
|
void transform_stat_info (char typeflag, struct tar_stat_info *stat_info);
|
||||||
char const *tartime (struct timespec t, bool full_time);
|
char const *tartime (struct timespec t, bool full_time);
|
||||||
|
|
||||||
#define OFF_FROM_HEADER(where) off_from_header (where, sizeof (where))
|
#define OFF_FROM_HEADER(where) off_from_header (where, sizeof (where))
|
||||||
@@ -975,7 +975,7 @@ enum
|
|||||||
void set_transform_expr (const char *expr);
|
void set_transform_expr (const char *expr);
|
||||||
bool transform_name (char **pinput, int type);
|
bool transform_name (char **pinput, int type);
|
||||||
bool transform_name_fp (char **pinput, int type,
|
bool transform_name_fp (char **pinput, int type,
|
||||||
char *(*fun)(char *, void *), void *);
|
char *(*fun) (char *, int), int dat);
|
||||||
bool transform_program_p (void);
|
bool transform_program_p (void);
|
||||||
|
|
||||||
/* Module suffix.c */
|
/* Module suffix.c */
|
||||||
|
|||||||
@@ -607,7 +607,7 @@ verify_volume (void)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
decode_header (current_header, ¤t_stat_info, ¤t_format, 1);
|
decode_header (current_header, ¤t_stat_info, ¤t_format, true);
|
||||||
diff_archive ();
|
diff_archive ();
|
||||||
tar_stat_destroy (¤t_stat_info);
|
tar_stat_destroy (¤t_stat_info);
|
||||||
}
|
}
|
||||||
|
|||||||
132
src/list.c
132
src/list.c
@@ -76,10 +76,8 @@ static char const base64_map[UCHAR_MAX + 1] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
decode_xform (char *file_name, void *data)
|
decode_xform (char *file_name, int type)
|
||||||
{
|
{
|
||||||
int type = *(int*)data;
|
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case XFORM_SYMLINK:
|
case XFORM_SYMLINK:
|
||||||
@@ -113,7 +111,7 @@ decode_xform (char *file_name, void *data)
|
|||||||
static bool
|
static bool
|
||||||
transform_member_name (char **pinput, int type)
|
transform_member_name (char **pinput, int type)
|
||||||
{
|
{
|
||||||
return transform_name_fp (pinput, type, decode_xform, &type);
|
return transform_name_fp (pinput, type, decode_xform, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -127,7 +125,7 @@ enforce_one_top_level (char **pfile_name)
|
|||||||
|
|
||||||
if (*p)
|
if (*p)
|
||||||
{
|
{
|
||||||
int pos = strlen (one_top_level_dir);
|
idx_t pos = strlen (one_top_level_dir);
|
||||||
if (strncmp (p, one_top_level_dir, pos) == 0)
|
if (strncmp (p, one_top_level_dir, pos) == 0)
|
||||||
{
|
{
|
||||||
if (ISSLASH (p[pos]) || p[pos] == 0)
|
if (ISSLASH (p[pos]) || p[pos] == 0)
|
||||||
@@ -143,7 +141,7 @@ enforce_one_top_level (char **pfile_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
transform_stat_info (int typeflag, struct tar_stat_info *stat_info)
|
transform_stat_info (char typeflag, struct tar_stat_info *stat_info)
|
||||||
{
|
{
|
||||||
if (typeflag == GNUTYPE_VOLHDR)
|
if (typeflag == GNUTYPE_VOLHDR)
|
||||||
/* Name transformations don't apply to volume headers. */
|
/* Name transformations don't apply to volume headers. */
|
||||||
@@ -193,7 +191,7 @@ read_and (void (*do_something) (void))
|
|||||||
/* Valid header. We should decode next field (mode) first.
|
/* Valid header. We should decode next field (mode) first.
|
||||||
Ensure incoming names are null terminated. */
|
Ensure incoming names are null terminated. */
|
||||||
decode_header (current_header, ¤t_stat_info,
|
decode_header (current_header, ¤t_stat_info,
|
||||||
¤t_format, 1);
|
¤t_format, true);
|
||||||
if (! name_match (current_stat_info.file_name)
|
if (! name_match (current_stat_info.file_name)
|
||||||
|| (time_option_initialized (newer_mtime_option)
|
|| (time_option_initialized (newer_mtime_option)
|
||||||
/* FIXME: We get mtime now, and again later; this causes
|
/* FIXME: We get mtime now, and again later; this causes
|
||||||
@@ -603,7 +601,7 @@ is_octal_digit (char c)
|
|||||||
e.g. print_header, that assumes decoded data. */
|
e.g. print_header, that assumes decoded data. */
|
||||||
void
|
void
|
||||||
decode_header (union block *header, struct tar_stat_info *stat_info,
|
decode_header (union block *header, struct tar_stat_info *stat_info,
|
||||||
enum archive_format *format_pointer, int do_user_group)
|
enum archive_format *format_pointer, bool do_user_group)
|
||||||
{
|
{
|
||||||
enum archive_format format;
|
enum archive_format format;
|
||||||
bool hbits;
|
bool hbits;
|
||||||
@@ -1088,7 +1086,7 @@ tartime (struct timespec t, bool full_time)
|
|||||||
stairstepping in the output. Make it too small and the output will
|
stairstepping in the output. Make it too small and the output will
|
||||||
almost always look ragged. Make it too large and the output will
|
almost always look ragged. Make it too large and the output will
|
||||||
be spaced out too far. */
|
be spaced out too far. */
|
||||||
static int ugswidth = 19;
|
static idx_t ugswidth = 19;
|
||||||
|
|
||||||
/* Width of printed time stamps. It grows if longer time stamps are
|
/* Width of printed time stamps. It grows if longer time stamps are
|
||||||
found (typically, those with nanosecond resolution). Like
|
found (typically, those with nanosecond resolution). Like
|
||||||
@@ -1101,24 +1099,10 @@ static void
|
|||||||
simple_print_header (struct tar_stat_info *st, union block *blk,
|
simple_print_header (struct tar_stat_info *st, union block *blk,
|
||||||
off_t block_ordinal)
|
off_t block_ordinal)
|
||||||
{
|
{
|
||||||
char modes[12];
|
char *temp_name
|
||||||
char const *time_stamp;
|
= (show_transformed_names_option
|
||||||
int time_stamp_len;
|
? (st->file_name ? st->file_name : st->orig_file_name)
|
||||||
char *temp_name;
|
: (st->orig_file_name ? st->orig_file_name : st->file_name));
|
||||||
|
|
||||||
/* These hold formatted ints. */
|
|
||||||
char uform[SYSINT_BUFSIZE];
|
|
||||||
char gform[SYSINT_BUFSIZE];
|
|
||||||
char *user, *group;
|
|
||||||
char size[2 * UINTMAX_STRSIZE_BOUND];
|
|
||||||
/* holds formatted size or major,minor */
|
|
||||||
int pad;
|
|
||||||
int sizelen;
|
|
||||||
|
|
||||||
if (show_transformed_names_option)
|
|
||||||
temp_name = st->file_name ? st->file_name : st->orig_file_name;
|
|
||||||
else
|
|
||||||
temp_name = st->orig_file_name ? st->orig_file_name : st->file_name;
|
|
||||||
|
|
||||||
if (block_number_option)
|
if (block_number_option)
|
||||||
{
|
{
|
||||||
@@ -1141,6 +1125,7 @@ simple_print_header (struct tar_stat_info *st, union block *blk,
|
|||||||
{
|
{
|
||||||
/* File type and modes. */
|
/* File type and modes. */
|
||||||
|
|
||||||
|
char modes[12];
|
||||||
modes[0] = '?';
|
modes[0] = '?';
|
||||||
switch (blk->header.typeflag)
|
switch (blk->header.typeflag)
|
||||||
{
|
{
|
||||||
@@ -1197,33 +1182,32 @@ simple_print_header (struct tar_stat_info *st, union block *blk,
|
|||||||
|
|
||||||
/* Time stamp. */
|
/* Time stamp. */
|
||||||
|
|
||||||
time_stamp = tartime (st->mtime, full_time_option);
|
char const *time_stamp = tartime (st->mtime, full_time_option);
|
||||||
time_stamp_len = strlen (time_stamp);
|
int time_stamp_len = strlen (time_stamp);
|
||||||
if (datewidth < time_stamp_len)
|
if (datewidth < time_stamp_len)
|
||||||
datewidth = time_stamp_len;
|
datewidth = time_stamp_len;
|
||||||
|
|
||||||
/* User and group names. */
|
/* User and group names. */
|
||||||
|
char uform[SYSINT_BUFSIZE];
|
||||||
|
char *user
|
||||||
|
= ((st->uname && st->uname[0] && current_format != V7_FORMAT
|
||||||
|
&& !numeric_owner_option)
|
||||||
|
? st->uname
|
||||||
|
: sysinttostr (st->stat.st_uid, TYPE_MINIMUM (uid_t),
|
||||||
|
TYPE_MAXIMUM (uid_t), uform));
|
||||||
|
|
||||||
if (st->uname
|
char gform[SYSINT_BUFSIZE];
|
||||||
&& st->uname[0]
|
char *group
|
||||||
&& current_format != V7_FORMAT
|
= ((st->gname && st->gname[0] && current_format != V7_FORMAT
|
||||||
&& !numeric_owner_option)
|
&& !numeric_owner_option)
|
||||||
user = st->uname;
|
? st->gname
|
||||||
else
|
: sysinttostr (st->stat.st_gid, TYPE_MINIMUM (gid_t),
|
||||||
user = sysinttostr (st->stat.st_uid, TYPE_MINIMUM (uid_t),
|
TYPE_MAXIMUM (gid_t), gform));
|
||||||
TYPE_MAXIMUM (uid_t), uform);
|
|
||||||
|
|
||||||
if (st->gname
|
|
||||||
&& st->gname[0]
|
|
||||||
&& current_format != V7_FORMAT
|
|
||||||
&& !numeric_owner_option)
|
|
||||||
group = st->gname;
|
|
||||||
else
|
|
||||||
group = sysinttostr (st->stat.st_gid, TYPE_MINIMUM (gid_t),
|
|
||||||
TYPE_MAXIMUM (gid_t), gform);
|
|
||||||
|
|
||||||
/* Format the file size or major/minor device numbers. */
|
/* Format the file size or major/minor device numbers. */
|
||||||
|
|
||||||
|
char size[2 * UINTMAX_STRSIZE_BOUND];
|
||||||
|
int sizelen;
|
||||||
switch (blk->header.typeflag)
|
switch (blk->header.typeflag)
|
||||||
{
|
{
|
||||||
case CHRTYPE:
|
case CHRTYPE:
|
||||||
@@ -1258,38 +1242,28 @@ simple_print_header (struct tar_stat_info *st, union block *blk,
|
|||||||
|
|
||||||
/* Figure out padding and print the whole line. */
|
/* Figure out padding and print the whole line. */
|
||||||
|
|
||||||
pad = strlen (user) + 1 + strlen (group) + 1 + sizelen;
|
idx_t pad = strlen (user) + 1 + strlen (group) + 1 + sizelen;
|
||||||
if (pad > ugswidth)
|
if (pad > ugswidth)
|
||||||
ugswidth = pad;
|
ugswidth = pad;
|
||||||
|
|
||||||
fprintf (stdlis, "%s %s/%s %*s %-*s",
|
fprintf (stdlis, "%s %s/%s", modes, user, group);
|
||||||
modes, user, group, ugswidth - pad + sizelen, size,
|
for (idx_t spaces = ugswidth - pad + 1; 0 < spaces; spaces--)
|
||||||
datewidth, time_stamp);
|
putc (' ', stdlis);
|
||||||
|
fprintf (stdlis, "%s %-*s ", size, datewidth, time_stamp);
|
||||||
fprintf (stdlis, " %s", quotearg (temp_name));
|
fputs (quotearg (temp_name), stdlis);
|
||||||
if (show_transformed_names_option && st->had_trailing_slash)
|
if (show_transformed_names_option && st->had_trailing_slash)
|
||||||
fputc ('/', stdlis);
|
fputc ('/', stdlis);
|
||||||
|
|
||||||
|
char const *link_to = " -> ";
|
||||||
switch (blk->header.typeflag)
|
switch (blk->header.typeflag)
|
||||||
{
|
{
|
||||||
case SYMTYPE:
|
|
||||||
fprintf (stdlis, " -> %s\n", quotearg (st->link_name));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LNKTYPE:
|
case LNKTYPE:
|
||||||
fprintf (stdlis, _(" link to %s\n"), quotearg (st->link_name));
|
link_to = _(" link to ");
|
||||||
break;
|
FALLTHROUGH;
|
||||||
|
case SYMTYPE:
|
||||||
default:
|
fputs (link_to, stdlis);
|
||||||
{
|
fputs (quotearg (st->link_name), stdlis);
|
||||||
char type_string[2];
|
FALLTHROUGH;
|
||||||
type_string[0] = blk->header.typeflag;
|
|
||||||
type_string[1] = '\0';
|
|
||||||
fprintf (stdlis, _(" unknown file type %s\n"),
|
|
||||||
quote (type_string));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AREGTYPE:
|
case AREGTYPE:
|
||||||
case REGTYPE:
|
case REGTYPE:
|
||||||
case GNUTYPE_SPARSE:
|
case GNUTYPE_SPARSE:
|
||||||
@@ -1318,6 +1292,11 @@ simple_print_header (struct tar_stat_info *st, union block *blk,
|
|||||||
fprintf (stdlis, _("--Continued at byte %jd--\n"),
|
fprintf (stdlis, _("--Continued at byte %jd--\n"),
|
||||||
intmax (OFF_FROM_HEADER (blk->oldgnu_header.offset)));
|
intmax (OFF_FROM_HEADER (blk->oldgnu_header.offset)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf (stdlis, _(" unknown file type %s\n"),
|
||||||
|
quote ((char []) {blk->header.typeflag, 0}));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fflush (stdlis);
|
fflush (stdlis);
|
||||||
@@ -1339,7 +1318,7 @@ print_volume_label (void)
|
|||||||
sizeof vblk.header.mtime);
|
sizeof vblk.header.mtime);
|
||||||
tar_stat_init (&vstat);
|
tar_stat_init (&vstat);
|
||||||
assign_string (&vstat.file_name, ".");
|
assign_string (&vstat.file_name, ".");
|
||||||
decode_header (&vblk, &vstat, &dummy, 0);
|
decode_header (&vblk, &vstat, &dummy, false);
|
||||||
assign_string (&vstat.file_name, volume_label);
|
assign_string (&vstat.file_name, volume_label);
|
||||||
simple_print_header (&vstat, &vblk, 0);
|
simple_print_header (&vstat, &vblk, 0);
|
||||||
tar_stat_destroy (&vstat);
|
tar_stat_destroy (&vstat);
|
||||||
@@ -1375,8 +1354,15 @@ print_for_mkdir (char *dirname, mode_t mode)
|
|||||||
fprintf (stdlis, _("block %jd: "),
|
fprintf (stdlis, _("block %jd: "),
|
||||||
intmax (current_block_ordinal ()));
|
intmax (current_block_ordinal ()));
|
||||||
|
|
||||||
fprintf (stdlis, "%s %*s %s\n", modes, ugswidth + 1 + datewidth,
|
fputs (modes, stdlis);
|
||||||
_("Creating directory:"), quotearg (dirname));
|
char const *creating = _("Creating directory:");
|
||||||
|
idx_t creating_len = strlen (creating);
|
||||||
|
for (idx_t spaces = max (1, 1 + ugswidth + 1 + datewidth - creating_len);
|
||||||
|
0 < spaces; spaces--)
|
||||||
|
putc (' ', stdlis);
|
||||||
|
fputs (creating, stdlis);
|
||||||
|
fputc(' ', stdlis);
|
||||||
|
fputs (quotearg (dirname), stdlis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1452,7 +1438,7 @@ test_archive_label (void)
|
|||||||
== HEADER_SUCCESS)
|
== HEADER_SUCCESS)
|
||||||
{
|
{
|
||||||
decode_header (current_header,
|
decode_header (current_header,
|
||||||
¤t_stat_info, ¤t_format, 0);
|
¤t_stat_info, ¤t_format, false);
|
||||||
if (current_header->header.typeflag == GNUTYPE_VOLHDR)
|
if (current_header->header.typeflag == GNUTYPE_VOLHDR)
|
||||||
ASSIGN_STRING_N (&volume_label, current_header->header.name);
|
ASSIGN_STRING_N (&volume_label, current_header->header.name);
|
||||||
|
|
||||||
|
|||||||
@@ -589,7 +589,7 @@ _transform_name_to_obstack (int flags, char *input, char **output)
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
transform_name_fp (char **pinput, int flags,
|
transform_name_fp (char **pinput, int flags,
|
||||||
char *(*fun)(char *, void *), void *dat)
|
char *(*fun) (char *, int), int dat)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
bool ret = _transform_name_to_obstack (flags, *pinput, &str);
|
bool ret = _transform_name_to_obstack (flags, *pinput, &str);
|
||||||
@@ -611,7 +611,7 @@ transform_name_fp (char **pinput, int flags,
|
|||||||
bool
|
bool
|
||||||
transform_name (char **pinput, int type)
|
transform_name (char **pinput, int type)
|
||||||
{
|
{
|
||||||
return transform_name_fp (pinput, type, NULL, NULL);
|
return transform_name_fp (pinput, type, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ update_archive (void)
|
|||||||
struct name *name;
|
struct name *name;
|
||||||
|
|
||||||
decode_header (current_header, ¤t_stat_info,
|
decode_header (current_header, ¤t_stat_info,
|
||||||
¤t_format, 0);
|
¤t_format, false);
|
||||||
transform_stat_info (current_header->header.typeflag,
|
transform_stat_info (current_header->header.typeflag,
|
||||||
¤t_stat_info);
|
¤t_stat_info);
|
||||||
archive_format = current_format;
|
archive_format = current_format;
|
||||||
|
|||||||
Reference in New Issue
Block a user