Vim-fork focused on extensibility and usability
Go to file
Nicolas Hillegeer 014febef22 coverity: fix BUFFER_SIZE_WARNING with str{n,l}cpy
Relates to issue #760

These coverity warnings are of the form:

>>>     CID 62602:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
>>>     Calling strncpy with a maximum size argument of 256 bytes...

This is caused by strncpy not alway NULL-terminated the destination buffer
(for example in the case where strlen(src) >= size(dst)). It's better to
replace that with (x)strlcpy, which always NULL-terminates.

Most of these are related to the set_api_error macro, which uses strncpy.
The error struct is used (for example) in msgpack_rpc_error, where strlen is
executed on it, so it needs to be NULL-terminated. (x)strlcpy, unlike
strncpy, always NULL-terminates the destination buffer.

Relevant parts of the coverity report:

*** CID 62602:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
/src/nvim/api/vim.c: 236 in vim_set_current_buffer()
230         if (try_end(err)) {
231           return;
232         }
233
234         char msg[256];
235         snprintf(msg, sizeof(msg),
              "failed to switch to buffer %d", (int)buffer);
>>>     CID 62602:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
>>>     Calling strncpy with a maximum size argument of 256 bytes on
>>>     destination array "err->msg" of size 256 bytes might leave the
>>>     destination string unterminated.
236         set_api_error(msg, err);
237         return;
238       }
239
240       try_end(err);
241     }

*** CID 62603:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
/src/nvim/api/private/helpers.c: 70 in try_end()
64       } else if (msg_list != NULL && *msg_list != NULL) {
65         int should_free;
66         char *msg = (char *)get_exception_string(*msg_list,
67                                                  ET_ERROR,
68                                                  NULL,
69                                                  &should_free);
>>>     CID 62603:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
>>>     Calling strncpy with a maximum size argument of 256 bytes on
>>>     destination array "err->msg" of size 256 bytes might leave the
>>>     destination string unterminated.
70         strncpy(err->msg, msg, sizeof(err->msg));
71         err->set = true;
72         free_global_msglist();
73
74         if (should_free) {
75           free(msg);
/src/nvim/api/private/helpers.c: 78 in try_end()
72         free_global_msglist();
73
74         if (should_free) {
75           free(msg);
76         }
77       } else if (did_throw) {
>>>     CID 62603:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
>>>     Calling strncpy with a maximum size argument of 256 bytes on
>>>     destination array "err->msg" of size 256 bytes might leave the
>>>     destination string unterminated.
78         set_api_error((char *)current_exception->value, err);
79       }
80
81       return err->set;
82     }
83

*** CID 62604:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
/src/nvim/api/private/helpers.c: 592 in set_option_value_err()
586                                              opt_flags)))
587       {
588         if (try_end(err)) {
589           return;
590         }
591
>>>     CID 62604:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
>>>     Calling strncpy with a maximum size argument of 256 bytes on
>>>     destination array "err->msg" of size 256 bytes might leave the
>>>     destination string unterminated.
592         set_api_error(errmsg, err);
593       }

*** CID 62605:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
/src/nvim/os/server.c: 114 in server_start()
108       if (addr_len > sizeof(ip) - 1) {
109         // Maximum length of a ip address buffer is 15(eg: 255.255.255.255)
110         addr_len = sizeof(ip);
111       }
112
113       // Extract the address part
>>>     CID 62605:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
>>>     Calling strncpy with a maximum size argument of 16 bytes on
>>>     destination array "ip" of size 16 bytes might leave the destination
>>>     string unterminated.
114       strncpy(ip, addr, addr_len);
115
116       int port = NEOVIM_DEFAULT_TCP_PORT;
117
118       if (*ip_end == ':') {
119         char *port_end;
/src/nvim/os/server.c: 88 in server_start()
82
83     void server_start(char *endpoint, ChannelProtocol prot)
84     {
85       char addr[ADDRESS_MAX_SIZE];
86
87       // Trim to `ADDRESS_MAX_SIZE`
>>>     CID 62605:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
>>>     Calling strncpy with a maximum size argument of 256 bytes on
>>>     destination array "addr" of size 256 bytes might leave the
>>>     destination string unterminated.
88       strncpy(addr, endpoint, sizeof(addr));
89
90       // Check if the server already exists
91       if (map_has(cstr_t)(servers, addr)) {
92         EMSG2("Already listening on %s", addr);
93         return;

*** CID 62606:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
/src/nvim/os/server.c: 186 in server_stop()
180     void server_stop(char *endpoint)
181     {
182       Server *server;
183       char addr[ADDRESS_MAX_SIZE];
184
185       // Trim to `ADDRESS_MAX_SIZE`
>>>     CID 62606:  Buffer not null terminated  (BUFFER_SIZE_WARNING)
>>>     Calling strncpy with a maximum size argument of 256 bytes on
>>>     destination array "addr" of size 256 bytes might leave the
>>>     destination string unterminated.
187
188       if ((server = map_get(cstr_t)(servers, addr)) == NULL) {
189         EMSG2("Not listening on %s", addr);
190         return;
191       }
2014-05-26 13:08:45 -03:00
cmake Generate a lua module to help pass build-related settings. 2014-05-03 10:36:54 -04:00
config Remove cryptography 2014-05-20 08:31:06 -03:00
contrib Introduce vim namespace: Contrib YCM: Fix style issues. 2014-05-19 16:24:44 +02:00
scripts API: Test: Setup basic test infrastructure 2014-05-23 16:06:59 -03:00
src/nvim coverity: fix BUFFER_SIZE_WARNING with str{n,l}cpy 2014-05-26 13:08:45 -03:00
test Introduce nvim namespace: Fix unit tests. 2014-05-15 20:46:02 +02:00
third-party Add --with-pic flag to msgpack configuration 2014-05-12 17:06:54 -03:00
.gitignore Introduce nvim namespace: Fix localization. 2014-05-15 20:46:02 +02:00
.travis.yml API: Test: Setup basic test infrastructure 2014-05-23 16:06:59 -03:00
.valgrind.supp Add helpers for debugging with valgrind 2014-04-05 11:05:31 -03:00
BACKERS.md I donated > 50 $, should be with URL 2014-04-20 10:35:18 -03:00
clint-files.txt Remove long_u: hashtab: Enable clint: Add to clint. 2014-05-24 01:17:51 +02:00
clint.py clint: disregard compound literal return 2014-05-18 06:45:39 -03:00
CMakeLists.txt Introduce nvim namespace: Fix build process. 2014-05-15 20:46:01 +02:00
CONTRIBUTING.md Update CONTRIBUTING.md with current info 2014-05-08 16:58:15 -05:00
Doxyfile Add basic Doxyfile. 2014-03-31 07:36:00 -03:00
Makefile Introduce nvim namespace: Fix build process. 2014-05-15 20:46:01 +02:00
neovim.rb Homebrew formula builds dependencies through make 2014-03-19 08:00:15 -03:00
README.md Add Reddit link to README. ref #704 2014-05-24 01:53:04 -04:00
uncrustify.cfg Issue #311 - Clean up blowfish.c/h, charset.c/h, diff.c/h, digraph.c/h, garray.c/h, hashtab.c/h, popupmnu.c/h, sha256.c/h, version.c/h. Update uncrustify to move logical operators to the beginning of the line when splitting. Also, clean up arabic.c/h and farsi.c/h 2014-03-16 12:00:41 -03:00
vim-license.txt include a copy of the Vim License 2014-02-22 11:57:44 +00:00

Neovim

Website | Google Group | Twitter | Reddit | Bountysource

Build Status Stories in Ready Coverage Status

Neovim is a project that seeks to aggressively refactor Vim in order to:

  • Simplify maintenance and encourage contributions
  • Split the work between multiple developers
  • Enable the implementation of new/modern user interfaces without any modifications to the core source
  • Improve extensibility with a new plugin architecture

For lots more details, see the wiki!

What's been done so far

  • Cleaned up source tree, leaving only core files
  • Removed support for legacy systems and moved to C99
    • Removed tons of FEAT_* macros with unifdef
    • Reduced C code from 300k lines to 170k
  • Enabled modern compiler features and optimizations
  • Formatted entire source with uncrustify
  • Replaced autotools build system with CMake
  • Implemented continuous integration and test coverage
  • Wrote 100+ new unit tests
  • Split large, monolithic files (misc1.c) into logical units (path.c, indent.c, garray.c, keymap.c, ...)
  • Implemented job control ("async")
  • Reworked out-of-memory handling resulting in greatly simplified control flow
  • Merged 50+ upstream patches (nearly caught up with upstream)
  • Removed 8.3 filename support
  • Changed to portable format specifiers (first step towards building on Windows)

What's being worked on now

  • Porting all IO to libuv
  • Lots of refactoring
  • A VimL => Lua transpiler
  • Formatting with clint.py
  • msg-pack remote API

How do I get it?

There is a formula for OSX/homebrew, a PKGBUILD for Arch Linux, and detailed instructions for building on other OSes.

See the wiki!

Community

Join the community on IRC in #neovim on Freenode or the mailing list

Contributing

...would be awesome! See the wiki for more details.

License

Vim itself is distributed under the terms of the Vim License. See vim-license.txt for details.

Vim also includes this message:

Vim is Charityware.  You can use and copy it as much as you like, but you are
encouraged to make a donation for needy children in Uganda.  Please see the
kcc section of the vim docs or visit the ICCF web site, available at these URLs:

        http://iccf-holland.org/
        http://www.vim.org/iccf/
        http://www.iccf.nl/

You can also sponsor the development of Vim.  Vim sponsors can vote for
features.  The money goes to Uganda anyway.