diff --git a/.gitignore b/.gitignore index 42e84c96..efbaa374 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,7 @@ test-driver ylwrap # A popular IDE *.code-workspace +*/*.o +*/*.lo +*/*.a +*/*.la diff --git a/build-deb.sh b/build-deb.sh index 134cd5a2..f0a05425 100755 --- a/build-deb.sh +++ b/build-deb.sh @@ -1,14 +1,31 @@ #!/usr/bin/env bash # -# Build a Debian package (.deb) from the pilot-link source tree. +# Build Debian packages from the pilot-link source tree. # Run from the project root. Requires build dependencies (see debian/control). # -set -e +set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR" && pwd)" cd "$ROOT_DIR" +sanitize_warning_error_flags() { + local token + local sanitized=() + + for token in $1; do + case "$token" in + -Werror|-Werror=*) + ;; + *) + sanitized+=("$token") + ;; + esac + done + + printf '%s ' "${sanitized[@]}" +} + # Optional: regenerate configure and Makefiles (use when building from git without committed configure) RECONFIGURE=false if [[ "${1:-}" == "--reconfigure" ]]; then @@ -37,9 +54,21 @@ fi echo "Building Debian package..." # -us: do not sign source package; -uc: do not sign .changes; -b: binary-only -# dpkg-buildflags can inject CFLAGS with "-Wformat =format-security" (space breaks the linker). -# Until this is fixed, use DEB_BUILD_MAINT_OPTIONS="hardening=-format" -# dpkg-buildpackage -us -uc -b "$@" -DEB_BUILD_MAINT_OPTIONS="hardening=-format" dpkg-buildpackage -us -uc -b "$@" +# Clear stale debhelper state so package splits/installs are recalculated cleanly. +rm -rf debian/.debhelper + +# configure.ac strips "-Werror" naively, which corrupts Debian flags like +# "-Werror=format-security" into "=format-security". Preserve the normal Debian +# flags but remove the -Werror entries before running the package build. +BUILD_CFLAGS="$(sanitize_warning_error_flags "$(dpkg-buildflags --get CFLAGS)")" +BUILD_CXXFLAGS="$(sanitize_warning_error_flags "$(dpkg-buildflags --get CXXFLAGS)")" +BUILD_CPPFLAGS="$(dpkg-buildflags --get CPPFLAGS)" +BUILD_LDFLAGS="$(dpkg-buildflags --get LDFLAGS)" + +CFLAGS="$BUILD_CFLAGS" \ +CXXFLAGS="$BUILD_CXXFLAGS" \ +CPPFLAGS="$BUILD_CPPFLAGS" \ +LDFLAGS="$BUILD_LDFLAGS" \ +dpkg-buildpackage -us -uc -b "$@" echo "Done. .deb and related files are in: $PARENT_DIR" diff --git a/build-debian.sh b/build-debian.sh new file mode 100755 index 00000000..16c7088c --- /dev/null +++ b/build-debian.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +exec "$SCRIPT_DIR/build-deb.sh" "$@" diff --git a/include/pi-md5.h.in b/include/pi-md5.h.in index 1cf3cbea..8f6fafb6 100644 --- a/include/pi-md5.h.in +++ b/include/pi-md5.h.in @@ -22,7 +22,7 @@ #if HAVE_STDINT_H #include #endif -#ifdef HAVE_INTTYPES_H || HAVE_STDINT_H +#if HAVE_INTTYPES_H || HAVE_STDINT_H #define UINT8 uint8_t #define UINT32 uint32_t #else diff --git a/libpisock/pi-header.c b/libpisock/pi-header.c index 9c9ae139..892ce034 100644 --- a/libpisock/pi-header.c +++ b/libpisock/pi-header.c @@ -29,7 +29,7 @@ #include void print_splash(const char *progname) { - char *patchlevel = ""; + const char *patchlevel = ""; fprintf(stderr, " DEPRECATED: The application is calling print_splash()\n"); #ifdef PILOT_LINK_PATCH @@ -41,9 +41,9 @@ void print_splash(const char *progname) { " `--------------------------------------------'\n" " This is %s, from pilot-link version %d.%d.%d%s\n\n" " Build target..: %s\n" - " Build date....: %s %s\n\n", + " Build date....: unavailable\n\n", progname, PILOT_LINK_VERSION, PILOT_LINK_MAJOR, PILOT_LINK_MINOR, - patchlevel, HOST_OS, __DATE__, __TIME__); + patchlevel, HOST_OS); printf(" pilot-link %d.%d.%d%s is covered under the GPL/LGPL\n", PILOT_LINK_VERSION, PILOT_LINK_MAJOR, PILOT_LINK_MINOR, patchlevel); diff --git a/libpisock/serial.c b/libpisock/serial.c index 0219937b..85bce10e 100644 --- a/libpisock/serial.c +++ b/libpisock/serial.c @@ -373,8 +373,10 @@ pi_serial_bind(pi_socket_t *ps, struct sockaddr *addr, size_t addrlen) char realport[4096]; # endif /* PATH_MAX */ #endif /* MAXPATHLEN */ + const char *port_for_messages = pa->pi_device; - realpath(pa->pi_device, realport); + if (realpath(pa->pi_device, realport) != NULL) + port_for_messages = realport; errno = save_errno; if (errno == ENOENT) { @@ -387,10 +389,10 @@ pi_serial_bind(pi_socket_t *ps, struct sockaddr *addr, size_t addrlen) } else if (errno == EACCES) { LOG((PI_DBG_DEV, PI_DBG_LVL_ERR, " Please check the " - "permissions on %s..\n", realport)); + "permissions on %s..\n", port_for_messages)); LOG((PI_DBG_DEV, PI_DBG_LVL_ERR, " Possible solution:\n\n\tchmod 0666 " - "%s\n\n", realport)); + "%s\n\n", port_for_messages)); } else if (errno == ENODEV) { while (count <= 5) { if (isatty(fileno(stdout))) { diff --git a/tests/packers.c b/tests/packers.c index 523f2d52..4b6c9f02 100644 --- a/tests/packers.c +++ b/tests/packers.c @@ -104,7 +104,7 @@ int test_memo() if (l != sizeof(MemoAppBlock)) { errors++; printf - ("1: unpack_MemoAppInfo returned incorrect length (got %d, expected %d)\n", + ("1: unpack_MemoAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(MemoAppBlock)); } @@ -113,7 +113,7 @@ int test_memo() if (l != sizeof(MemoAppBlock)) { errors++; printf - ("2: unpack_MemoAppInfo returned incorrect length (got %d, expected %d)\n", + ("2: unpack_MemoAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(MemoAppBlock)); } @@ -142,7 +142,7 @@ int test_memo() if (l != sizeof(MemoAppBlock)) { errors++; printf - ("5: unpack_MemoAppInfo returned incorrect length (got %d, expected %d)\n", + ("5: unpack_MemoAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(MemoAppBlock)); } @@ -206,7 +206,7 @@ int test_memo() if (l != sizeof(MemoAppBlock)) { errors++; printf - ("7: pack_MemoAppInfo returned incorrect allocation length (got %d, expected %d)\n", + ("7: pack_MemoAppInfo returned incorrect allocation length (got %d, expected %zu)\n", l, sizeof(MemoAppBlock)); } @@ -231,7 +231,7 @@ int test_memo() if (l != sizeof(MemoAppBlock)) { errors++; printf - ("10: pack_MemoAppInfo returned incorrect length (got %d, expected %d)\n", + ("10: pack_MemoAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(MemoAppBlock)); } @@ -272,7 +272,7 @@ int test_memo() if (RecordBuffer->used != sizeof(MemoRecord)) { errors++; printf - ("15: pack_MemoRecord returned incorrect allocation length (got %d, expected %d)\n", + ("15: pack_MemoRecord returned incorrect allocation length (got %zu, expected %zu)\n", RecordBuffer->used, sizeof(MemoRecord)); } @@ -353,7 +353,7 @@ int test_address() if (l != sizeof(AddressAppBlock)) { errors++; printf - ("1: unpack_AddressAppInfo returned incorrect length (got %d, expected %d)\n", + ("1: unpack_AddressAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(AddressAppBlock)); } @@ -364,7 +364,7 @@ int test_address() if (l != sizeof(AddressAppBlock)) { errors++; printf - ("2: unpack_AddressAppInfo returned incorrect length (got %d, expected %d)\n", + ("2: unpack_AddressAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(AddressAppBlock)); } @@ -397,7 +397,7 @@ int test_address() if (l != sizeof(AddressAppBlock)) { errors++; printf - ("5: unpack_AddressAppInfo returned incorrect length (got %d, expected %d)\n", + ("5: unpack_AddressAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(AddressAppBlock)); } @@ -459,7 +459,7 @@ int test_address() if (l != sizeof(AddressAppBlock)) { errors++; printf - ("7: pack_AddressAppInfo returned incorrect allocation length (got %d, expected %d)\n", + ("7: pack_AddressAppInfo returned incorrect allocation length (got %d, expected %zu)\n", l, sizeof(AddressAppBlock)); } @@ -485,7 +485,7 @@ int test_address() if (l != sizeof(AddressAppBlock)) { errors++; printf - ("10: pack_AddressAppInfo returned incorrect length (got %d, expected %d)\n", + ("10: pack_AddressAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(AddressAppBlock)); } @@ -535,7 +535,7 @@ int test_address() if (RecordBuffer->used != sizeof(AddressRecord)) { errors++; printf - ("15: pack_Address returned incorrect length (got %d, expected %d)\n", + ("15: pack_Address returned incorrect length (got %zu, expected %zu)\n", RecordBuffer->used, sizeof(AddressRecord)); } @@ -599,7 +599,7 @@ int test_appointment() if (l != sizeof(AppointmentAppBlock)) { errors++; printf - ("1: unpack_AppointmentAppInfo returned incorrect length (got %d, expected %d)\n", + ("1: unpack_AppointmentAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(AppointmentAppBlock)); } @@ -610,7 +610,7 @@ int test_appointment() if (l != sizeof(AppointmentAppBlock)) { errors++; printf - ("2: unpack_AppointmentAppInfo returned incorrect length (got %d, expected %d)\n", + ("2: unpack_AppointmentAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(AppointmentAppBlock)); } @@ -643,7 +643,7 @@ int test_appointment() if (l != sizeof(AppointmentAppBlock)) { errors++; printf - ("5: unpack_AppointmentAppInfo returned incorrect length (got %d, expected %d)\n", + ("5: unpack_AppointmentAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(AppointmentAppBlock)); } @@ -708,7 +708,7 @@ int test_appointment() if (l != sizeof(AppointmentAppBlock)) { errors++; printf - ("7: pack_AppointmentAppInfo returned incorrect allocation length (got %d, expected %d)\n", + ("7: pack_AppointmentAppInfo returned incorrect allocation length (got %d, expected %zu)\n", l, sizeof(AppointmentAppBlock)); } @@ -734,7 +734,7 @@ int test_appointment() if (l != sizeof(AppointmentAppBlock)) { errors++; printf - ("10: pack_AppointmentAppInfo returned incorrect length (got %d, expected %d)\n", + ("10: pack_AppointmentAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(AppointmentAppBlock)); } @@ -786,7 +786,7 @@ int test_appointment() if (RecordBuffer->used != sizeof(AppointmentRecord)) { errors++; printf - ("15: pack_Appointment returned incorrect length (got %d, expected %d)\n", + ("15: pack_Appointment returned incorrect length (got %zu, expected %zu)\n", RecordBuffer->used, sizeof(AppointmentRecord)); } @@ -842,7 +842,7 @@ int test_todo() if (l != sizeof(ToDoAppBlock)) { errors++; printf - ("1: unpack_ToDoAppInfo returned incorrect length (got %d, expected %d)\n", + ("1: unpack_ToDoAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(ToDoAppBlock)); } @@ -851,7 +851,7 @@ int test_todo() if (l != sizeof(ToDoAppBlock)) { errors++; printf - ("2: unpack_ToDoAppInfo returned incorrect length (got %d, expected %d)\n", + ("2: unpack_ToDoAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(ToDoAppBlock)); } @@ -878,7 +878,7 @@ int test_todo() if (l != sizeof(ToDoAppBlock)) { errors++; printf - ("5: unpack_ToDoAppInfo returned incorrect length (got %d, expected %d)\n", + ("5: unpack_ToDoAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(ToDoAppBlock)); } @@ -942,7 +942,7 @@ int test_todo() if (l != sizeof(ToDoAppBlock)) { errors++; printf - ("7: pack_ToDoAppInfo returned incorrect allocation length (got %d, expected %d)\n", + ("7: pack_ToDoAppInfo returned incorrect allocation length (got %d, expected %zu)\n", l, sizeof(ToDoAppBlock)); } @@ -967,7 +967,7 @@ int test_todo() if (l != sizeof(ToDoAppBlock)) { errors++; printf - ("10: pack_ToDoAppInfo returned incorrect length (got %d, expected %d)\n", + ("10: pack_ToDoAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(ToDoAppBlock)); } @@ -1021,8 +1021,8 @@ int test_todo() if (RecordBuffer->used != sizeof(ToDoRecord)) { errors++; printf - ("15: pack_ToDo returned incorrect length (got %d, expected %d)\n", - l, sizeof(ToDoRecord)); + ("15: pack_ToDo returned incorrect length (got %zu, expected %zu)\n", + RecordBuffer->used, sizeof(ToDoRecord)); } if (memcmp(RecordBuffer->data, ToDoRecord, sizeof(ToDoRecord))) { @@ -1087,7 +1087,7 @@ int test_expense() if (l != sizeof(ExpenseAppBlock)) { errors++; printf - ("1: unpack_ExpenseAppInfo returned incorrect length (got %d, expected %d)\n", + ("1: unpack_ExpenseAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(ExpenseAppBlock)); } @@ -1098,7 +1098,7 @@ int test_expense() if (l != sizeof(ExpenseAppBlock)) { errors++; printf - ("2: unpack_ExpenseAppInfo returned incorrect length (got %d, expected %d)\n", + ("2: unpack_ExpenseAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(ExpenseAppBlock)); } @@ -1116,7 +1116,7 @@ int test_expense() if (l != sizeof(ExpenseAppBlock)) { errors++; printf - ("3: unpack_ExpenseAppInfo returned incorrect length (got %d, expected %d)\n", + ("3: unpack_ExpenseAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(ExpenseAppBlock)); } @@ -1181,7 +1181,7 @@ int test_expense() if (l != sizeof(ExpenseAppBlock)) { errors++; printf - ("5: pack_ExpenseAppInfo returned incorrect allocation length (got %d, expected %d)\n", + ("5: pack_ExpenseAppInfo returned incorrect allocation length (got %d, expected %zu)\n", l, sizeof(ExpenseAppBlock)); } @@ -1207,7 +1207,7 @@ int test_expense() if (l != sizeof(ExpenseAppBlock)) { errors++; printf - ("8: pack_ExpenseAppInfo returned incorrect length (got %d, expected %d)\n", + ("8: pack_ExpenseAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(ExpenseAppBlock)); } @@ -1230,7 +1230,7 @@ int test_expense() if (l != sizeof(ExpenseRecord)) { errors++; printf - ("11: unpack_Expense returned incorrect length (got %d, expected %d)\n", + ("11: unpack_Expense returned incorrect length (got %d, expected %zu)\n", l, sizeof(ExpenseRecord)); } @@ -1257,7 +1257,7 @@ int test_expense() if (l != sizeof(ExpenseRecord)) { errors++; printf - ("13: pack_Expense returned incorrect allocation length (got %d, expected %d)\n", + ("13: pack_Expense returned incorrect allocation length (got %d, expected %zu)\n", l, sizeof(ExpenseRecord)); } @@ -1282,7 +1282,7 @@ int test_expense() if (l != sizeof(ExpenseRecord)) { errors++; printf - ("16: pack_Expense returned incorrect length (got %d, expected %d)\n", + ("16: pack_Expense returned incorrect length (got %d, expected %zu)\n", l, sizeof(ExpenseRecord)); } @@ -1348,7 +1348,7 @@ int test_mail() if (l != sizeof(MailAppBlock)) { errors++; printf - ("1: unpack_MailAppInfo returned incorrect length (got %d, expected %d)\n", + ("1: unpack_MailAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailAppBlock)); } @@ -1357,7 +1357,7 @@ int test_mail() if (l != sizeof(MailAppBlock)) { errors++; printf - ("2: unpack_MailAppInfo returned incorrect length (got %d, expected %d)\n", + ("2: unpack_MailAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailAppBlock)); } @@ -1373,7 +1373,7 @@ int test_mail() if (l != sizeof(MailAppBlock)) { errors++; printf - ("3: unpack_MailAppInfo returned incorrect length (got %d, expected %d)\n", + ("3: unpack_MailAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailAppBlock)); } @@ -1438,7 +1438,7 @@ int test_mail() if (l != sizeof(MailAppBlock)) { errors++; printf - ("5: pack_MailAppInfo returned incorrect allocation length (got %d, expected %d)\n", + ("5: pack_MailAppInfo returned incorrect allocation length (got %d, expected %zu)\n", l, sizeof(MailAppBlock)); } @@ -1463,7 +1463,7 @@ int test_mail() if (l != sizeof(MailAppBlock)) { errors++; printf - ("8: pack_MailAppInfo returned incorrect length (got %d, expected %d)\n", + ("8: pack_MailAppInfo returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailAppBlock)); } @@ -1486,7 +1486,7 @@ int test_mail() if (l != sizeof(MailRecord)) { errors++; printf - ("11: unpack_Mail returned incorrect length (got %d, expected %d)\n", + ("11: unpack_Mail returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailRecord)); } @@ -1513,7 +1513,7 @@ int test_mail() if (l != sizeof(MailRecord)) { errors++; printf - ("13: pack_Mail returned incorrect allocation length (got %d, expected %d)\n", + ("13: pack_Mail returned incorrect allocation length (got %d, expected %zu)\n", l, sizeof(MailRecord)); } @@ -1537,7 +1537,7 @@ int test_mail() if (l != sizeof(MailRecord)) { errors++; printf - ("16: pack_Mail returned incorrect length (got %d, expected %d)\n", + ("16: pack_Mail returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailRecord)); } @@ -1561,7 +1561,7 @@ int test_mail() if (l != sizeof(MailSyncPreference)) { errors++; printf - ("19: unpack_MailSyncPref returned incorrect length (got %d, expected %d)\n", + ("19: unpack_MailSyncPref returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailSyncPreference)); } @@ -1572,7 +1572,7 @@ int test_mail() if (l != sizeof(MailSyncPreference)) { errors++; printf - ("20: unpack_MailSyncPref returned incorrect length (got %d, expected %d)\n", + ("20: unpack_MailSyncPref returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailSyncPreference)); } @@ -1583,7 +1583,7 @@ int test_mail() if (l != sizeof(MailSyncPreference)) { errors++; printf - ("21: unpack_MailSyncPref returned incorrect length (got %d, expected %d)\n", + ("21: unpack_MailSyncPref returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailSyncPreference)); } @@ -1610,7 +1610,7 @@ int test_mail() if (l != sizeof(MailSyncPreference)) { errors++; printf - ("23: pack_MailSyncPref returned incorrect allocation length (got %d, expected %d)\n", + ("23: pack_MailSyncPref returned incorrect allocation length (got %d, expected %zu)\n", l, sizeof(MailSyncPreference)); } @@ -1636,7 +1636,7 @@ int test_mail() if (l != sizeof(MailSyncPreference)) { errors++; printf - ("26: pack_MailSyncPref returned incorrect length (got %d, expected %d)\n", + ("26: pack_MailSyncPref returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailSyncPreference)); } @@ -1662,7 +1662,7 @@ int test_mail() if (l != sizeof(MailSigPreference)) { errors++; printf - ("29: unpack_MailSigPref returned incorrect length (got %d, expected %d)\n", + ("29: unpack_MailSigPref returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailSyncPreference)); } @@ -1673,7 +1673,7 @@ int test_mail() if (l != sizeof(MailSigPreference)) { errors++; printf - ("30: unpack_MailSigPref returned incorrect length (got %d, expected %d)\n", + ("30: unpack_MailSigPref returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailSyncPreference)); } @@ -1684,7 +1684,7 @@ int test_mail() if (l != sizeof(MailSigPreference)) { errors++; printf - ("31: unpack_MailSigPref returned incorrect length (got %d, expected %d)\n", + ("31: unpack_MailSigPref returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailSyncPreference)); } @@ -1711,7 +1711,7 @@ int test_mail() if (l != sizeof(MailSigPreference)) { errors++; printf - ("33: pack_MailSignaturePref returned incorrect allocation length (got %d, expected %d)\n", + ("33: pack_MailSignaturePref returned incorrect allocation length (got %d, expected %zu)\n", l, sizeof(MailSigPreference)); } @@ -1737,7 +1737,7 @@ int test_mail() if (l != sizeof(MailSigPreference)) { errors++; printf - ("36: pack_MailSignaturePref returned incorrect length (got %d, expected %d)\n", + ("36: pack_MailSignaturePref returned incorrect length (got %d, expected %zu)\n", l, sizeof(MailSigPreference)); }