Skip to content

Consider not overriding _FORTIFY_SOURCE= define: port to c99 flexible arrays #5581

@trofi

Description

@trofi

Describe the bug
vim is not _FORTIFY_SOURCE=2 clean (uses char[1] array). This causes the following problems:

  • [minor] configure.ac occasionally fails to catch new way to define _FORTIFY_SOURCE=2 and users get cryptic buffer overflow crashes
  • [major] gcc assumes that array are 1-byte long and can produce invalid code (similar to what glibc does on _FORTIFY_SOURCE=2 by introspecting array length)

To Reproduce
It's a downstream version of https://bugs.gentoo.org/706324 where gcc-10 was not detected and _FORTIFY_SOURCE=2 default was missed (worked around in #5580).

Expected behavior
vim should build and run on _FORTIFY_SOURCE=2 compiler.

Environment (please complete the following information):

  • Vim version: 8.2.0114
  • OS: Gentoo
  • Terminal: alactitty-0.4.1

If vim can afford using flexible array members (https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html) it might use those:

--- a/src/structs.h
+++ b/src/structs.h
@@ -1414,7 +1414,7 @@ struct dictitem_S
 {
     typval_T	di_tv;		// type and value of the variable
     char_u	di_flags;	// flags (only used for variable)
-    char_u	di_key[1];	// key (actually longer!)
+    char_u	di_key[];	// key (actually longer!)
 };
 typedef struct dictitem_S dictitem_T;

I did not check if the rest of code does not rely on sizeof(struct dictitem_S).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions