• Thomas Haller's avatar
    shared: add nm_strerror_native() to replace strerror() and g_strerror() · e1ca3bf7
    Thomas Haller authored
    We have various options for strerror(), with ups and downsides:
    
    - strerror()
    
        - returns pointer that is overwritten on next call. It's convenient
          to use, but dangerous.
    
        - not thread-safe.
    
        - not guaranteed to be UTF-8.
    
    - strerror_r()
    
        - takes input buffer and is less convenient to use. At least, we
          are in control of when the buffer gets overwritten.
    
        - there is a Posix/XSI and a glibc variant, making it sligthly
          inconvenient to used. This could be solved by a wrapper we implement.
    
        - thread-safe.
    
        - not guaranteed to be UTF-8.
    
    - g_strerror()
    
        - convenient and safe to use. Also the buffer is never released for the
          remainder of the program.
    
        - passing untrusted error numbers to g_strerror() can result in a
          denial of service, as the internal buffer grows until out-of-memory.
    
        - thread-safe.
    
        - guaranteed to be UTF-8 (depending on locale).
    
    Add our own wrapper nm_strerror_native(). It is:
    
        - convenient to use (returning a buffer that does not require
          management).
    
        - slightly dangerous as the buffer gets overwritten on the next call
          (like strerror()).
    
        - thread-safe.
    
        - guaranteed to be UTF-8 (depending on locale).
    
        - doesn't keep an unlimited cache of strings, unlike g_strerror().
    
    You can't have it all. g_strerror() is leaking all generated error messages.
    I think that is unacceptable, because it would mean we need to
    keep track where our error numbers come from (and trust libraries we
    use to only set a restricted set of known error numbers).
    e1ca3bf7
Name
Last commit
Last update
clients Loading commit data...
contrib Loading commit data...
data Loading commit data...
dispatcher Loading commit data...
docs Loading commit data...
examples Loading commit data...
introspection Loading commit data...
libnm Loading commit data...
libnm-core Loading commit data...
libnm-glib Loading commit data...
libnm-util Loading commit data...
m4 Loading commit data...
man Loading commit data...
po Loading commit data...
shared Loading commit data...
src Loading commit data...
tools Loading commit data...
vapi Loading commit data...
.dir-locals.el Loading commit data...
.gitignore Loading commit data...
.gitlab-ci.yml Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTING Loading commit data...
COPYING Loading commit data...
ChangeLog Loading commit data...
MAINTAINERS Loading commit data...
Makefile.am Loading commit data...
Makefile.examples Loading commit data...
Makefile.glib Loading commit data...
Makefile.vapigen Loading commit data...
NEWS Loading commit data...
NetworkManager.pc.in Loading commit data...
README Loading commit data...
TODO Loading commit data...
autogen.sh Loading commit data...
config-extra.h.meson Loading commit data...
config.h.meson Loading commit data...
configure.ac Loading commit data...
linker-script-binary.ver Loading commit data...
linker-script-devices.ver Loading commit data...
linker-script-settings.ver Loading commit data...
meson.build Loading commit data...
meson_options.txt Loading commit data...
valgrind.suppressions Loading commit data...
zanata.xml Loading commit data...