NetworkManager/src/core/settings
Thomas Haller 370316fc3e
ifcfg-rh: allocate exact buffer in _escape_ansic()
Previously, we would allocate a buffer of the worst case, that is,
4 times the number of bytes, in case all of them require octal escaping.

Coverity doesn't like _escape_ansic() for another reason:

   Error: NULL_RETURNS (CWE-476): [#def298]
   NetworkManager-1.31.5/src/core/settings/plugins/ifcfg-rh/shvar.c:161: returned_null: "g_malloc" returns "NULL".
   NetworkManager-1.31.5/src/core/settings/plugins/ifcfg-rh/shvar.c:161: alias: Assigning: "q" = "dest = g_malloc(strlen(source) * 4UL + 1UL + 3UL)". Both pointers are now "NULL".
   NetworkManager-1.31.5/src/core/settings/plugins/ifcfg-rh/shvar.c:163: dereference: Incrementing a pointer which might be null: "q".
   #  161|       q = dest = g_malloc(strlen(source) * 4 + 1 + 3);
   #  162|
   #  163|->     *q++ = '$';
   #  164|       *q++ = '\'';
   #  165|

It doesn't recognize that g_malloc() shouldn't return NULL (because
we never request zero bytes).

I am not sure how to avoid that, but let's rework the code to first count
how many characters we exactly need. It think that should also help with
the coverity warning.

Doing exact allocation requires first to count the number of required
bytes. It still might be worth it, because we might keep the allocated
strings a bit longer around.
2021-05-26 15:45:59 +02:00
..
plugins ifcfg-rh: allocate exact buffer in _escape_ansic() 2021-05-26 15:45:59 +02:00
nm-agent-manager.c build: move "libnm-core/" to "src/" and split it 2021-02-18 19:46:51 +01:00
nm-agent-manager.h all: move "src/" directory to "src/core/" 2021-02-04 09:45:55 +01:00
nm-secret-agent.c all: Replace deprecated NM_CONNECTION_SERIALIZE_* flags 2021-04-01 17:19:15 +02:00
nm-secret-agent.h all: move "src/" directory to "src/core/" 2021-02-04 09:45:55 +01:00
nm-settings-connection.c core: drop deprecated PropertiesChanged D-Bus signal (API BREAK) 2021-05-14 10:57:34 +02:00
nm-settings-connection.h settings: Drop nm_settings_connection_clear_secrets 2021-04-23 15:00:51 +02:00
nm-settings-plugin.c build: move "libnm-core/" to "src/" and split it 2021-02-18 19:46:51 +01:00
nm-settings-plugin.h all: move "src/" directory to "src/core/" 2021-02-04 09:45:55 +01:00
nm-settings-storage.c all: add "src/core/nm-default-daemon.h" as replacement for "nm-default.h" 2021-02-09 12:38:18 +01:00
nm-settings-storage.h all: move "src/" directory to "src/core/" 2021-02-04 09:45:55 +01:00
nm-settings-utils.c all: add "src/core/nm-default-daemon.h" as replacement for "nm-default.h" 2021-02-09 12:38:18 +01:00
nm-settings-utils.h all: move "src/" directory to "src/core/" 2021-02-04 09:45:55 +01:00
nm-settings.c core: drop deprecated PropertiesChanged D-Bus signal (API BREAK) 2021-05-14 10:57:34 +02:00
nm-settings.h all: move "src/" directory to "src/core/" 2021-02-04 09:45:55 +01:00