]> xenbits.xensource.com Git - people/royger/freebsd.git/commitdiff
contrib/bc: MFC version 5.2.2
authorStefan Eßer <se@FreeBSD.org>
Sat, 5 Feb 2022 21:26:36 +0000 (22:26 +0100)
committerStefan Eßer <se@FreeBSD.org>
Fri, 4 Mar 2022 20:19:50 +0000 (21:19 +0100)
This release assigns a default value to the internal program name
variable in case the program is invoked with argv[0] == NULL.

There was no security issue: the prevuous program version would have
been immediately terminated due to a NULL dereference.

(cherry picked from commit 00698711dee1d990d3db9c41bf58394e589eecfe)

contrib/bc/NEWS.md
contrib/bc/configure.sh
contrib/bc/include/lang.h
contrib/bc/include/version.h
contrib/bc/include/vm.h
contrib/bc/src/main.c
contrib/bc/src/program.c

index 5d0126b821a8f478e224ab713c96c32b24f95d84..9a354e537d9faef8928ba370d1b465b0324d3640 100644 (file)
@@ -1,5 +1,13 @@
 # News
 
+## 5.2.2
+
+This is a production release that fixes one bug, a segmentation fault if
+`argv[0]` equals `NULL`.
+
+This is not a critical bug; there will be no vulnerability as far as I can tell.
+There is no need to update if you do not wish to.
+
 ## 5.2.1
 
 This is a production release that fixes two parse bugs when in POSIX standard
index 76ffb2b9a18e7406513a5683c6ef9a074620be2c..fc66ffc51066e07e81faf446966051ea2a07c152 100755 (executable)
@@ -36,7 +36,7 @@ builddir=$(pwd)
 . "$scriptdir/scripts/functions.sh"
 
 # Simply prints the help message and quits based on the argument.
-# @param val  The value to pass to exit. Must be an integer.
+# @param msg  The help message to print.
 usage() {
 
        if [ $# -gt 0 ]; then
@@ -95,7 +95,7 @@ usage() {
        printf '    -f, --force\n'
        printf '        Force use of all enabled options, even if they do not work. This\n'
        printf '        option is to allow the maintainer a way to test that certain options\n'
-       printf '        are not failing invisibly. (Development only.)'
+       printf '        are not failing invisibly. (Development only.)\n'
        printf '    -g, --debug\n'
        printf '        Build in debug mode. Adds the "-g" flag, and if there are no\n'
        printf '        other CFLAGS, and "-O" was not given, this also adds the "-O0"\n'
@@ -535,7 +535,7 @@ gen_std_test_targets() {
 # This allows `make test_bc_errors` and `make test_dc_errors` to run in
 # parallel.
 #
-# @param name        Which calculator to generate tests for.
+# @param name  Which calculator to generate tests for.
 gen_err_tests() {
 
        _gen_err_tests_name="$1"
index 705aca35df1c55ad13ad45780d364474a471dab1..09b0d60728063bfac8964ec96e01b268bba0bbd4 100644 (file)
@@ -37,6 +37,9 @@
 #define BC_LANG_H
 
 #include <stdbool.h>
+#if BC_C11
+#include <assert.h>
+#endif // BC_C11
 
 #include <status.h>
 #include <vector.h>
@@ -324,6 +327,11 @@ typedef enum BcInst {
 
 } BcInst;
 
+#if BC_C11
+static_assert(BC_INST_INVALID <= UCHAR_MAX,
+              "Too many instructions to fit into an unsigned char");
+#endif // BC_C11
+
 /// Used by maps to identify where items are in the array.
 typedef struct BcId {
 
index eca73baf508f223aefd5bf6f058c90c1aacf2ba1..0c4122528e7deae6e4da17b7b23045abacd88fca 100644 (file)
@@ -37,6 +37,6 @@
 #define BC_VERSION_H
 
 /// The current version.
-#define VERSION 5.2.1
+#define VERSION 5.2.2
 
 #endif // BC_VERSION_H
index d6f698fb1e6d7e14eaf86abe0daf8989e327d96e..6f69712a804bb6eef0609a633dab6ea6c2bba58f 100644 (file)
@@ -545,8 +545,10 @@ typedef struct BcVm {
        /// The messages for each error.
        const char *err_msgs[BC_ERR_NELEMS];
 
+#if BC_ENABLE_NLS
        /// The locale.
        const char *locale;
+#endif // BC_ENABLE_NLS
 
 #endif // !BC_ENABLE_LIBRARY
 
index 38c87a415f2bc16c3a123a464a7abc383d4eb601..3146f983787edc175c1abb6f7c57c1ea2e7585a1 100644 (file)
@@ -37,7 +37,9 @@
 #include <stdlib.h>
 #include <string.h>
 
+#if BC_ENABLE_NLS
 #include <locale.h>
+#endif // BC_ENABLE_NLS
 
 #ifndef _WIN32
 #include <libgen.h>
@@ -56,16 +58,34 @@ int main(int argc, char *argv[]) {
        char *name;
        size_t len = strlen(BC_EXECPREFIX);
 
+#if BC_ENABLE_NLS
        // Must set the locale properly in order to have the right error messages.
        vm.locale = setlocale(LC_ALL, "");
+#endif // BC_ENABLE_NLS
 
        // Set the start pledge().
        bc_pledge(bc_pledge_start, NULL);
 
-       // Figure out the name of the calculator we are using. We can't use basename
-       // because it's not portable, but yes, this is stripping off the directory.
-       name = strrchr(argv[0], BC_FILE_SEP);
-       vm.name = (name == NULL) ? argv[0] : name + 1;
+       // Sometimes, argv[0] can be NULL. Better make sure to be robust against it.
+       if (argv[0] != NULL) {
+
+               // Figure out the name of the calculator we are using. We can't use
+               // basename because it's not portable, but yes, this is stripping off
+               // the directory.
+               name = strrchr(argv[0], BC_FILE_SEP);
+               vm.name = (name == NULL) ? argv[0] : name + 1;
+       }
+       else
+       {
+#if !DC_ENABLED
+               vm.name = "bc";
+#elif !BC_ENABLED
+               vm.name = "dc";
+#else
+               // Just default to bc in that case.
+               vm.name = "bc";
+#endif
+       }
 
        // If the name is longer than the length of the prefix, skip the prefix.
        if (strlen(vm.name) > len) vm.name += len;
index bc5b88011638f76e055bf5072f358b3974203d6e..8ec1a011a26d9a9c37f835c71a8ba43391b3f1a0 100644 (file)
@@ -2718,7 +2718,6 @@ void bc_program_exec(BcProgram *p) {
        while (ip->idx < func->code.len)
 #endif // !BC_HAS_COMPUTED_GOTO
        {
-
                BC_SIG_ASSERT_NOT_LOCKED;
 
 #if BC_HAS_COMPUTED_GOTO