aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-06-19 14:56:28 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2009-06-19 14:56:28 +0300
commit8e7537ce0e443bb757c10854a8a04110ca8ebe3d (patch)
tree6d8ba46f0015e8ceb60dcf0535524acd5fda445b
parent1034f14aafe2074d3d3fc6240f32291d85f76e37 (diff)
downloadcpio-8e7537ce0e443bb757c10854a8a04110ca8ebe3d.tar.gz
cpio-8e7537ce0e443bb757c10854a8a04110ca8ebe3d.tar.bz2
Make sure the structs used for I/O mapping are not padded.
* am/flushleft.m4, am/pack.m4: New files. * Makefile.am (ACLOCAL_AMFLAGS): Add -I am. * bootstrap: Fix arguments to aclocal. * configure.ac: Call CPIO_PACKED_STRUCTS. * src/cpiohdr.h: Ensure old_cpio_header, old_ascii_header and new_ascii_header are packed.
-rw-r--r--Makefile.am2
-rw-r--r--am/flushleft.m428
-rw-r--r--am/pack.m467
-rwxr-xr-xbootstrap3
-rw-r--r--configure.ac2
-rw-r--r--src/cpiohdr.h32
6 files changed, 128 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am
index e173b9d..d742d17 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA.
-ACLOCAL_AMFLAGS = -I m4
+ACLOCAL_AMFLAGS = -I m4 -I am
AUTOMAKE_OPTIONS = gnits 1.8 dist-bzip2 std-options
diff --git a/am/flushleft.m4 b/am/flushleft.m4
new file mode 100644
index 0000000..d1cc11d
--- /dev/null
+++ b/am/flushleft.m4
@@ -0,0 +1,28 @@
+# This file is part of GNU cpio
+# Copyright (C) 2009 Free Software Foundation
+#
+# GNU cpio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU cpio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU cpio. If not, see <http://www.gnu.org/licenses/>.
+
+dnl CPIO_FLUSHLEFT -- remove all whitespace at the beginning of lines
+dnl This is useful for c-code which may include cpp statements
+dnl
+dnl WARNING: When editing this macro, make sure your editor does not
+dnl clobber the regexp argument to m4_bpatsubst: it must contain one
+dnl space and one tab (ASCII 9) character.
+dnl
+AC_DEFUN([CPIO_FLUSHLEFT],
+ [m4_changequote(`,')dnl
+ m4_bpatsubst(`$1', `^[ ]+')
+ m4_changequote([,])])dnl
+
diff --git a/am/pack.m4 b/am/pack.m4
new file mode 100644
index 0000000..c03c948
--- /dev/null
+++ b/am/pack.m4
@@ -0,0 +1,67 @@
+# This file is part of GNU cpio
+# Copyright (C) 2009 Free Software Foundation
+#
+# GNU cpio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU cpio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU cpio. If not, see <http://www.gnu.org/licenses/>.
+
+# CPIO_PACKED_STRUCTS is based on code from ClamAV
+AC_DEFUN([CPIO_PACKED_STRUCTS],[
+ dnl check for __attribute__((packed))
+ AC_MSG_CHECKING([for structure packing via __attribute__((packed))])
+ AC_CACHE_VAL(cpio_cv_have_attrib_packed,[
+ AC_TRY_COMPILE(,
+ [struct { int i __attribute__((packed)); } s; ],
+ [have_attrib_packed=yes],
+ [have_attrib_packed=no])
+ ])
+ AC_MSG_RESULT($have_attrib_packed)
+
+ if test "$have_attrib_packed" = no; then
+ AC_MSG_CHECKING(for structure packing via pragma)
+ AC_CACHE_VAL(cpio_cv_have_pragma_pack,[
+ AC_TRY_RUN(CPIO_FLUSHLEFT([
+ int main(int argc, char **argv) {
+ #pragma pack(1)
+ struct { char c; long l; } s;
+ return sizeof(s)==sizeof(s.c)+sizeof(s.l) ? 0:1; } ]),
+ [have_pragma_pack=yes],
+ [have_pragma_pack=no])
+ ])
+ AC_MSG_RESULT($have_pragma_pack)
+ if test "$have_pragma_pack" = yes; then
+ AC_DEFINE(HAVE_PRAGMA_PACK, 1, "pragma pack")
+ else
+ AC_MSG_CHECKING(for structure packing via hppa/hp-ux pragma)
+ AC_CACHE_VAL(cpio_cv_have_pragma_pack_hpux,[
+ AC_TRY_RUN(CPIO_FLUSHLEFT([
+ /* hppa/hp-ux wants pragma outside of function */
+ #pragma pack 1
+ struct { char c; long l; } s;
+ int main(int argc, char **argv) {
+ return sizeof(s)==sizeof(s.c)+sizeof(s.l) ? 0:1; } ]),
+ [have_pragma_pack_hpux=yes],
+ [have_pragma_pack_hpux=no])
+ ])
+ AC_MSG_RESULT($have_pragma_pack_hpux)
+ AC_DEFINE(HAVE_PRAGMA_PACK_HPPA, 1, "pragma pack hppa/hp-ux style")
+ fi
+ fi
+
+ if test "${have_attrib_packed}${have_pragma_pack}$have_pragma_pack_hpux" = "nonono"; then
+ AC_MSG_ERROR(Need to know how to pack structures with this compiler)
+ fi
+
+ if test "$have_attrib_packed" = yes; then
+ AC_DEFINE(HAVE_ATTRIB_PACKED, 1, [attrib packed])
+ fi
+])
diff --git a/bootstrap b/bootstrap
index 9226995..58c4a04 100755
--- a/bootstrap
+++ b/bootstrap
@@ -669,9 +669,10 @@ copy_files ${PAXUTILS_SRCDIR}/paxlib lib
# Reconfigure, getting other files.
+aclocal_flags=`sed -n 's/ACLOCAL_AMFLAGS *=//p' Makefile.am`
for command in \
libtool \
- 'aclocal --force -I m4' \
+ "aclocal --force $aclocal_flags" \
'autoconf --force' \
'autoheader --force' \
'automake --add-missing --copy --force-missing';
diff --git a/configure.ac b/configure.ac
index d4c73d8..198ea12 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,7 +54,7 @@ gl_INIT
cpio_PAXUTILS
# Additional system dependencies (for mingw)
CPIO_SYSDEP
-
+CPIO_PACKED_STRUCTS
AC_SUBST(CPIO_MT_PROG)
AC_ARG_ENABLE(mt,
diff --git a/src/cpiohdr.h b/src/cpiohdr.h
index 29ad858..6231ec8 100644
--- a/src/cpiohdr.h
+++ b/src/cpiohdr.h
@@ -22,6 +22,18 @@
#include <cpio.h>
+#ifdef HAVE_ATTRIB_PACKED
+#define ATTRIB_PACKED __attribute__((packed))
+#endif
+
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack(1)
+#endif
+
+#ifdef HAVE_PRAGMA_PACK_HPPA
+#pragma pack 1
+#endif
+
struct old_cpio_header
{
unsigned short c_magic;
@@ -35,8 +47,15 @@ struct old_cpio_header
unsigned short c_mtimes[2];
unsigned short c_namesize;
unsigned short c_filesizes[2];
-};
+} ATTRIB_PACKED;
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack(1)
+#endif
+
+#ifdef HAVE_PRAGMA_PACK_HPPA
+#pragma pack 1
+#endif
struct old_ascii_header
{
char c_magic[6];
@@ -50,7 +69,7 @@ struct old_ascii_header
char c_mtime[11];
char c_namesize[6];
char c_filesize[11];
-};
+} ATTRIB_PACKED;
/* "New" portable format and CRC format:
@@ -62,6 +81,13 @@ struct old_ascii_header
/* All the fields in the header are ISO 646 (approximately ASCII) strings
of hexadecimal numbers, left padded, not NUL terminated: */
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack(1)
+#endif
+
+#ifdef HAVE_PRAGMA_PACK_HPPA
+#pragma pack 1
+#endif
struct new_ascii_header
{
char c_magic[6]; /* "070701" for "new" portable format
@@ -80,7 +106,7 @@ struct new_ascii_header
char c_namesize[8]; /* count includes terminating NUL in pathname */
char c_chksum[8]; /* 0 for "new" portable format; for CRC format
the sum of all the bytes in the file */
-};
+} ATTRIB_PACKED;
struct cpio_file_stat /* Internal representation of a CPIO header */
{

Return to:

Send suggestions and report system problems to the System administrator.