project/uci.git
5 years agolua: fix error handling
Petr Štetiar [Mon, 4 Nov 2019 23:45:30 +0000 (00:45 +0100)]
lua: fix error handling

scan-build from clang version 9 has reported following issues:

 uci.c:389:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~
 uci.c:393:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_NOTFOUND;
                ^     ~~~~~~~~~~~~~~~~
 uci.c:417:4: warning: Value stored to 'err' is never read
                        err = UCI_ERR_INVAL;
                        ^     ~~~~~~~~~~~~~
 uci.c:524:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~
 uci.c:533:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~
 uci.c:565:4: warning: Value stored to 'err' is never read
                        err = UCI_ERR_INVAL;
                        ^     ~~~~~~~~~~~~~
 uci.c:575:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~
 uci.c:584:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~
 uci.c:642:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~
 uci.c:651:3: warning: Value stored to 'err' is never read
                err = UCI_ERR_INVAL;
                ^     ~~~~~~~~~~~~~

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agoucimap: fix possible use of memory after it is freed
Petr Štetiar [Mon, 4 Nov 2019 23:43:46 +0000 (00:43 +0100)]
ucimap: fix possible use of memory after it is freed

scan-build from clang version 9 has reported following issue:

 ucimap.c:710:8: warning: Use of memory after it is freed
        err = ucimap_parse_options(map, sm, sd, s);
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agodelta: prevent possible null pointer use
Petr Štetiar [Mon, 4 Nov 2019 23:39:46 +0000 (00:39 +0100)]
delta: prevent possible null pointer use

scan-build from clang version 9 has reported following issue:

 delta.c:39:13: warning: Null pointer passed to 1st parameter expecting 'nonnull'
        int size = strlen(section) + 1;
                   ^~~~~~~~~~~~~~~

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agocli: remove unused variable assigment
Petr Štetiar [Mon, 4 Nov 2019 23:28:15 +0000 (00:28 +0100)]
cli: remove unused variable assigment

scan-build from clang version 9 has reported following issue:

 cli.c:574:8: warning: Although the value stored to 'ret' is used in the enclosing expression, the value is never actually read from 'ret'
                if ((ret = uci_parse_argument(ctx, input, &str, &argv[i])) != UCI_OK) {
                     ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agolua: fix memory leak in set method
Petr Štetiar [Mon, 4 Nov 2019 22:08:26 +0000 (23:08 +0100)]
lua: fix memory leak in set method

scan-build from clang version 9 has reported following issue:

 uci.c:624:12: warning: Potential leak of memory pointed to by 's'
       return luaL_error(L, "Cannot set an uci option to an empty table value");
              ^~~~~~~~~~

valgrind confirmed it on the supplied test case:

 ==31013== 8 bytes in 1 blocks are definitely lost in loss record 1 of 1
 ==31013==    by 0x56C49B9: strdup (strdup.c:42)

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agolua: fix memory leak in changes method
Petr Štetiar [Mon, 4 Nov 2019 21:41:18 +0000 (22:41 +0100)]
lua: fix memory leak in changes method

Configs returned by uci_list_configs call are not freed when not needed,
leading to the memory leak. While at it make the code cleaner.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agotests: add cram based unit tests
Petr Štetiar [Mon, 4 Nov 2019 19:41:55 +0000 (20:41 +0100)]
tests: add cram based unit tests

I find them more flexible then shunit2 ones.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agolua: fix copy&paste in error string
Petr Štetiar [Mon, 4 Nov 2019 19:09:30 +0000 (20:09 +0100)]
lua: fix copy&paste in error string

When uci_set_confdir fails we should say so.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agocli: fix realloc issue spotted by cppcheck
Petr Štetiar [Mon, 4 Nov 2019 18:46:13 +0000 (19:46 +0100)]
cli: fix realloc issue spotted by cppcheck

Cppcheck 1.90 dev reports following:

 cli.c:117:4: error: Common realloc mistake: 'typestr' nulled but not freed upon failure [memleakOnRealloc]
    typestr = realloc(typestr, maxlen);
    ^

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agoiron out all extra compiler warnings
Petr Štetiar [Mon, 4 Nov 2019 17:21:44 +0000 (18:21 +0100)]
iron out all extra compiler warnings

gcc 9.1 on x86/64 has reported following issues:

 list.c:140:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 file.c:572:51: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 file.c:850:15: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 file.c:865:15: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 delta.c:199:6: error: this statement may fall through [-Werror=implicit-fallthrough=]
 parse.c:80:12: error: this statement may fall through [-Werror=implicit-fallthrough=]
 parse.c:81:12: error: this statement may fall through [-Werror=implicit-fallthrough=]
 file.c:572:51: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 file.c:850:15: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 file.c:865:15: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 delta.c:199:6: error: this statement may fall through [-Werror=implicit-fallthrough=]
 parse.c:80:12: error: this statement may fall through [-Werror=implicit-fallthrough=]
 parse.c:81:12: error: this statement may fall through [-Werror=implicit-fallthrough=]
 ucimap.c:146:16: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 ucimap.c:151:17: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 ucimap.c:243:34: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 ucimap.c:247:9: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 ucimap.c:254:39: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 ucimap.c:258:9: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 ucimap.c:285:34: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 ucimap.c:363:17: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 ucimap.c:563:12: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 ucimap.c:753:18: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 ucimap.c:879:17: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agotests: shunit2: run all tests under Valgrind by default
Petr Štetiar [Mon, 4 Nov 2019 17:18:36 +0000 (18:18 +0100)]
tests: shunit2: run all tests under Valgrind by default

The more tests, the better.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agocmake: enable extra compiler checks
Petr Štetiar [Mon, 4 Nov 2019 17:02:35 +0000 (18:02 +0100)]
cmake: enable extra compiler checks

Let's enforce additional automatic checks enforced by the compiler in
order to catch possible errors during compilation.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agocmake: build Lua module only if enabled
Petr Štetiar [Mon, 4 Nov 2019 15:18:37 +0000 (16:18 +0100)]
cmake: build Lua module only if enabled

Makes the resulting lua/CMakeLists.txt file simpler.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agotests: shunit2: fix issues reported by shellcheck
Petr Štetiar [Fri, 1 Nov 2019 09:26:38 +0000 (10:26 +0100)]
tests: shunit2: fix issues reported by shellcheck

 In tests.sh line 10:
 [ -x $UCI_BIN ] || {
      ^------^ SC2086: Double quote to prevent globbing and word splitting.

 In tests.sh line 63:
 for suite in $(ls ${SCRIPTS_DIR}/*)
              ^--------------------^ SC2045: Iterating over ls output is fragile. Use globs.

 In tests.sh line 65:
  cat ${suite} >> ${FULL_SUITE}
             ^------^ SC2086: Double quote to prevent globbing and word splitting.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agoadd initial GitLab CI support
Petr Štetiar [Thu, 17 Oct 2019 12:55:02 +0000 (14:55 +0200)]
add initial GitLab CI support

Uses currently proof-of-concept openwrt-ci[1] in order to:

 * improve the quality of the codebase in various areas
 * decrease code review time and help merging contributions faster
 * get automagic feedback loop on various platforms and tools
   - out of tree build with OpenWrt SDK on following targets:
     * ath79-generic
     * imx6-generic
     * malta-be
     * mvebu-cortexa53
   - out of tree native build on x86/64 with GCC (versions 7, 8, 9) and Clang 9
   - out of tree native x86/64 static code analysis with cppcheck and
     scan-build from Clang 9

1. https://gitlab.com/ynezz/openwrt-ci/

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agotests: shunit2: make it working under CMake
Petr Štetiar [Fri, 1 Nov 2019 08:28:07 +0000 (09:28 +0100)]
tests: shunit2: make it working under CMake

uci is being passed from CMake as environment variable.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agocmake: add unit testing option and shunit2 tests
Petr Štetiar [Fri, 1 Nov 2019 08:13:42 +0000 (09:13 +0100)]
cmake: add unit testing option and shunit2 tests

For convenient tests invocation.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agotest: move shunit2 tests under standalone subdirectory
Petr Štetiar [Fri, 1 Nov 2019 08:11:48 +0000 (09:11 +0100)]
test: move shunit2 tests under standalone subdirectory

So we could start adding other tests as well. While at it rename the
parent directory from test to the more common tests name.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
5 years agobuild: Add -Wclobbered to detect problems with longjmp
Hauke Mehrtens [Fri, 1 Nov 2019 14:06:01 +0000 (15:06 +0100)]
build: Add -Wclobbered to detect problems with longjmp

When we jump back to a save point in UCI_THROW() with longjmp all the
registers will be reset to the old values when we called UCI_TRAP_SAVE()
last time, but the memory is not restored. This will revert all the
variables which are stored in registers, but not the variables stored on
the stack.

Mark all the variables which the compiler could put into a register as
volatile to store them safely on the stack and make sure they have the
defined current values also after longjmp was called.

The setjmp() manage says the following:
----------------------------------------------------------------------
The  compiler  may  optimize  variables into registers, and longjmp()
may restore the values of other registers in addition to the stack
pointer and program counter.  Consequently, the values of automatic
variables are unspecified after a call to longjmp() if they meet all the
following criteria:
* they are local to the function that made the corresponding setjmp()
  call;
* their values are changed between the calls to setjmp() and longjmp();
  and
* they are not declared as volatile.
---------------------------------------------------------------------

The -Wclobbered compiler option warns about all variables which are
written after setjmp() was called, not all of them could cause problems,
but to make sure to catch all real problems add this warning and fix all
occurrences of this warning.

This also activates a compiler warning which should warn us in such
cases.
This could fix some potential problems in error paths like the one
reported in CVE-2019-15513.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
5 years agoutil: Fix error path
Hauke Mehrtens [Fri, 1 Nov 2019 11:02:13 +0000 (12:02 +0100)]
util: Fix error path

Unlock and close the stream in case some file operations in
uci_open_stream() fail.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
5 years agouci/file: replace mktemp() with mkstemp()
Maxim Gorbachyov [Fri, 19 Jul 2019 06:46:42 +0000 (23:46 -0700)]
uci/file: replace mktemp() with mkstemp()

mktemp is unsafe to use as well as deprecated by POSIX.1-2008. uClibc-ng
optionally does not include it when SuSv3 legacy functions are disabled.

Signed-off-by: Maxim Gorbachyov <maxim.gorbachyov@gmail.com>
Signed-off-by: Rosen Penev <rosenp@gmail.com>
5 years agouci: fix options list of section after type change
Sven Eckelmann [Fri, 17 May 2019 12:30:06 +0000 (14:30 +0200)]
uci: fix options list of section after type change

A section can store its name in the same memory region as the section
(after the actual section object). The object is then reallocated when the
type is later changed via an uci_set. But the original address of the
section is (indirectly) stored in the section list, the object and the
object list (HEAD) of this section.

But only the section list was fixed in commit 4fb6a564b8ee ("clean up
uci_set") after the realloc finished. Traversing the object list or
accessing the section pointer caused heap-use-after-free errors.

Reported-by: Charlemagne Lasse <charlemagnelasse@gmail.com>
Fixes: 4fb6a564b8ee ("clean up uci_set")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
6 years agodelta: fix parsing malformed delta lines
Yousong Zhou [Sat, 11 Aug 2018 06:31:28 +0000 (06:31 +0000)]
delta: fix parsing malformed delta lines

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
6 years agouci: fix a potential use-after-free in uci_set()
Jordan Miner [Sun, 25 Mar 2018 01:30:07 +0000 (20:30 -0500)]
uci: fix a potential use-after-free in uci_set()

When calling uci_set() to update an option, if ptr->o != NULL and
ptr->option == NULL, then uci_expand_ptr() will set ptr->option to
ptr->o->e.name (or the caller could set ptr->option to that value). In
this case, the option will be freed just before calling
uci_alloc_option() with ptr->option, which was just freed.

Signed-off-by: Jordan Miner <jminer7@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agolist: only record ordering deltas if element position changed
Jo-Philipp Wich [Thu, 15 Mar 2018 23:21:58 +0000 (00:21 +0100)]
list: only record ordering deltas if element position changed

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
6 years agocmake: Fix cli shared linking against ubox
Andre Castro [Fri, 2 Feb 2018 12:04:44 +0000 (12:04 +0000)]
cmake: Fix cli shared linking against ubox

The 'ubox' library used in 'cli' target is not using the output of the
'find_library' command. This is a problem when the 'ubox' library is not
located on the standard system library locations.

Use the CMake variable 'ubox', output of 'find_library' call that points
to the library found on the system, instead of hardcoding the library's
name to 'ubox'.

Signed-off-by: Andre Castro <andre.castro.sw@gmail.com>
6 years agolua: additionally return name when looking up sections
Jo-Philipp Wich [Sun, 31 Dec 2017 10:30:32 +0000 (11:30 +0100)]
lua: additionally return name when looking up sections

Return the resolved name in addition to the type when looking up sections
through `get()` - for example a `cursor:get("firewall", "@rule[0]")` will
now return two values in the form ("rule", "cfg0a92bd") instead of only
the type name.

This is mainly useful to resolve extended section names without having to
reimplement the section count logic in Lua code.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
6 years agolua: support extended section notation
Jo-Philipp Wich [Sun, 31 Dec 2017 10:08:22 +0000 (11:08 +0100)]
lua: support extended section notation

Wrap uci_lookup_ptr() to enable extended section format lookups
when the passed section literal is in "@" notation.

This allows calls in the form `cursor:get("conf", "@stype[0]", "opt")`
which is useful to resolve options in numerically indexed anonymous
sections.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
6 years agolist: remove unncessary increment of n_section (FS#1182)
Hans Dedecker [Thu, 21 Dec 2017 10:56:32 +0000 (11:56 +0100)]
list: remove unncessary increment of n_section (FS#1182)

The package n_section counter is already incremented in uci_alloc_section;
so no need to increment it again in uci_fixup_section.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agofile: remove unnecessary uci_fixup_section calls
Hans Dedecker [Thu, 21 Dec 2017 10:56:31 +0000 (11:56 +0100)]
file: remove unnecessary uci_fixup_section calls

This makes it clear uci_fixup_section only needs to be called in
uci_add_section when an unnamed section is added.

Before it was a bit misleading when walking through the code seeing
uci_fixup_section being called in uci_parse_config and uci_import.
When uci config is parsed via these functions uci_add_section is
eventually called which in the end constructs a name for an unnamed
section.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoAdd bitfield_set function from libubox.
Stijn Tintel [Thu, 17 Aug 2017 14:27:20 +0000 (16:27 +0200)]
Add bitfield_set function from libubox.

The bitfield functions and macros where removed from libubox. Add the
bitfield_set function which is used by uci, and prefix it with uci_.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
7 years agofile: remove redundant NULL check on return value of uci_realloc()
Yousong Zhou [Tue, 21 Mar 2017 03:15:12 +0000 (11:15 +0800)]
file: remove redundant NULL check on return value of uci_realloc()

Because the check will be done by uci_realloc itself.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
7 years agobuild: fix BUILD_STATIC
Yousong Zhou [Tue, 21 Mar 2017 03:15:11 +0000 (11:15 +0800)]
build: fix BUILD_STATIC

- Build libuci.a in addition to libuci.so
 - Build uci cli utitlity statically if BUILD_STATIC is enabled

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
8 years agoFix skipping directories in uci_list_config_files
Michal 'vorner' Vaner [Tue, 22 Nov 2016 15:50:24 +0000 (16:50 +0100)]
Fix skipping directories in uci_list_config_files

Don't create a hole in the array of configs if there's a directory. Such
a hole would be mistaken for the end of the array.

Signed-off-by: Michal 'vorner' Vaner <michal.vaner@nic.cz>
8 years agoRevert "mandatory anonymous section identifier"
Felix Fietkau [Thu, 10 Nov 2016 12:13:00 +0000 (13:13 +0100)]
Revert "mandatory anonymous section identifier"

This reverts commits:
df72af474075 "mandatory anonymous section identifier"
2eb9c097e392 "cli: remove now-defunct UCI_FLAG_EXPORT_NAME support"
fe45f97302cb "test: adjust for auto-naming anonymous sections"

After some discussion we came to the conclusion that we need a different
fix.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agouci/lua: add explicit close() method
Dirk Feytons [Thu, 29 Sep 2016 15:39:57 +0000 (17:39 +0200)]
uci/lua: add explicit close() method

This allows a caller to explicitly free the cursor as soon as it is
no longer needed instead of having to wait for the garbage collector.

Signed-off-by: Dirk Feytons <dirk.feytons@gmail.com>
8 years agouci/lua: add list_configs() function
Dirk Feytons [Thu, 29 Sep 2016 15:39:56 +0000 (17:39 +0200)]
uci/lua: add list_configs() function

Returns an array with all the available configs.

Signed-off-by: Dirk Feytons <dirk.feytons@gmail.com>
8 years agotest: adjust for auto-naming anonymous sections
Felix Fietkau [Thu, 6 Oct 2016 18:04:52 +0000 (20:04 +0200)]
test: adjust for auto-naming anonymous sections

Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agocli: remove now-defunct UCI_FLAG_EXPORT_NAME support
Felix Fietkau [Thu, 6 Oct 2016 18:02:36 +0000 (20:02 +0200)]
cli: remove now-defunct UCI_FLAG_EXPORT_NAME support

Preserve command line switches for compatibility reasons

Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agomandatory anonymous section identifier
Antonio Paunovic [Thu, 6 Oct 2016 13:47:56 +0000 (15:47 +0200)]
mandatory anonymous section identifier

This change makes sure there are no more anonymous (unnamed) sections
in configuration files. Previously it was optional and now the choice
is being removed.

All sections will have generated identifiers. This is important because
anonymous sections will be simpler to manipulate.

Signed-off-by: Antonio Paunovic <antonio.paunovic@sartura.hr>
Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
8 years agoprojects/uci: lua: use built in pkg-config support for alternatives
Karl Palsson [Fri, 15 Apr 2016 15:12:18 +0000 (15:12 +0000)]
projects/uci: lua: use built in pkg-config support for alternatives

Different distributions have different names for the lua 5.1 package.
Use cmake's built in pkg-config support to search for the first one,
rather than running it explicitly and searching for a single version.

Signed-off-by: Karl Palsson <karlp@remake.is>
8 years agofile: write through symlinks on uci commit
Jo-Philipp Wich [Thu, 31 Mar 2016 00:06:12 +0000 (02:06 +0200)]
file: write through symlinks on uci commit

The rename() syscall operates on the destination path directly, therfore
resolve the real path before doing the rename to not clobber the destination
in case it is a symlink pointing to another file.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
8 years agocmake: Add ubox library and include dir lookup
Petr Štetiar [Sat, 5 Mar 2016 13:59:14 +0000 (14:59 +0100)]
cmake: Add ubox library and include dir lookup

Otherwise cmake uses files from system which sometimes isn't wanted, ie.
for testing.

Signed-off-by: Petr Å tetiar <ynezz@true.cz>
8 years agocli: fix uci show output for anonymous sections (#21781)
Felix Fietkau [Tue, 2 Feb 2016 17:12:54 +0000 (18:12 +0100)]
cli: fix uci show output for anonymous sections (#21781)

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
8 years agofile: raise parse error on conflicting section types in strict mode
Jo-Philipp Wich [Thu, 5 Nov 2015 18:15:40 +0000 (19:15 +0100)]
file: raise parse error on conflicting section types in strict mode

If strict mode is enabled and we're parsing a config file with multiple
sections of the same name but different types, then raise a parse error
to notify the user that the subsequent section declaration would shadow
all prior ones of the same name.

The error would be triggered by a config like that:

  config typeA example
    option test 1

  config typeB example
    option test 2

In such a case, libuci will raise this error:

  uci: Parse error (section of different type overwrites prior section with same name) at line 4, byte 23

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
8 years agofile: defer checking the tmpfile until it is actually needed.
Felix Fietkau [Mon, 11 Jan 2016 12:27:26 +0000 (13:27 +0100)]
file: defer checking the tmpfile until it is actually needed.

Avoids creating useless entries in the kernel dentry cache

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 years agoremove list.h
Felix Fietkau [Wed, 11 Nov 2015 12:17:11 +0000 (13:17 +0100)]
remove list.h

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 years agolua: remove pointless double check of autoload flag
Karl Palsson [Thu, 5 Nov 2015 17:27:48 +0000 (17:27 +0000)]
lua: remove pointless double check of autoload flag

In e2b1433b the autoload param went from being an enumerated type to a
simple boolean.  Drop the pointless double check of this flag.

Signed-off-by: Karl Palsson <karlp@remake.is>
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 years agolua: fix invocation of foreach() with nil type and implicit self
Jo-Philipp Wich [Thu, 5 Nov 2015 17:47:34 +0000 (18:47 +0100)]
lua: fix invocation of foreach() with nil type and implicit self

The check for nil on the 2nd argument misses the offset in order to skip over
implicit self which results in
  `bad argument #2 to 'foreach' (string expected, got nil)`
when invoking `uci.cursor():foreach("test", nil, function(s) end)`.

The same call works fine when using dot instead of colon notation.

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
9 years agofile: remove unnecessary sync() call
Felix Fietkau [Thu, 27 Aug 2015 12:40:57 +0000 (14:40 +0200)]
file: remove unnecessary sync() call

It can be too expensive during filesystem initialization, and it is not
required for atomic handling of config changes.
If the write gets interrupted, the config file will always contain
either the new state or the old state

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 years agotests: add test case for parsing long option values.
Yousong Zhou [Mon, 25 May 2015 12:32:43 +0000 (20:32 +0800)]
tests: add test case for parsing long option values.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agofile.c: lift the 4096 bytes line length limit.
Yousong Zhou [Mon, 25 May 2015 12:32:42 +0000 (20:32 +0800)]
file.c: lift the 4096 bytes line length limit.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agodelta: catch error when parsing delta line.
Yousong Zhou [Mon, 25 May 2015 12:32:41 +0000 (20:32 +0800)]
delta: catch error when parsing delta line.

Reported by sarumpaet [1]

 [1] uci fails to handle long values properly,
     https://github.com/openwrt/packages/issues/1231

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agocli: suppress printing error messages when -q is specified.
Yousong Zhou [Mon, 25 May 2015 12:32:40 +0000 (20:32 +0800)]
cli: suppress printing error messages when -q is specified.

 - Introduce cli_error() for printing local errors.
 - Convert existing fprintf(stderr, ) and perror() to cli_error().
 - N.B. error messages will still be printed if they occured before -q
   flag was parsed.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agouci: properly close input before exit
Hans Dedecker [Tue, 28 Apr 2015 14:07:27 +0000 (16:07 +0200)]
uci: properly close input before exit

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
9 years agofile: reset parsing position on starting over a newline.
Yousong Zhou [Thu, 9 Apr 2015 13:48:47 +0000 (21:48 +0800)]
file: reset parsing position on starting over a newline.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agotests: add test coverage for comment lines within batch commands.
Yousong Zhou [Thu, 9 Apr 2015 13:48:46 +0000 (21:48 +0800)]
tests: add test coverage for comment lines within batch commands.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agodelta: fix adding new savedir.
Yousong Zhou [Wed, 1 Apr 2015 12:44:23 +0000 (20:44 +0800)]
delta: fix adding new savedir.

Newly added savedir should be at the last position while
uci_add_delta_path() will add it to the position second to the last.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agotests: add test coverage for uci export with -P option.
Yousong Zhou [Wed, 1 Apr 2015 12:44:22 +0000 (20:44 +0800)]
tests: add test coverage for uci export with -P option.

 - With "uci -P xxx/ export", changes in "xxx/" should be applied last.
 - With "uci -p xxx/ commit", changes in "xxx/" should be applied before
   ctx->savedir.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agoFix delta path handling.
Yousong Zhou [Tue, 31 Mar 2015 16:20:18 +0000 (00:20 +0800)]
Fix delta path handling.

 - Make ctx->savedir sit at the end of ctx->delta_path.
 - Add notes to uci_set_savedir() and uci_add_delta_path() to document
   the behaviour changes.

9 years agotests: add test cases for -P and -p options.
Yousong Zhou [Tue, 31 Mar 2015 16:20:17 +0000 (00:20 +0800)]
tests: add test cases for -P and -p options.

9 years agolua: restore return value of require('uci') to module table.
Yousong Zhou [Wed, 18 Mar 2015 04:44:45 +0000 (12:44 +0800)]
lua: restore return value of require('uci') to module table.

Before commit "b121dd lua: add lua 5.2 compatibility changes", the
module table was filled by luaL_register() which would leave the table
at the top of the stack.  But in current code the module table will be
popped by lua_setglobal() causing the return value defaulting to boolean
value true.

Also fix the return value of luaopen_uci() to 1 to indicate the number
of return value on stack.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agocli: fix return value of package_cmd().
Yousong Zhou [Wed, 18 Mar 2015 04:44:44 +0000 (12:44 +0800)]
cli: fix return value of package_cmd().

It's a bug revealed by commit 446e774 "cli: properly unload package
before quit".  The current code would exit with value 1 even if
uci_export() succceeded.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agotestenv: test for exit status of "uci export".
Yousong Zhou [Wed, 18 Mar 2015 04:44:43 +0000 (12:44 +0800)]
testenv: test for exit status of "uci export".

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agoAdd a few notes on the return value of uci_lookup_ptr().
Yousong Zhou [Sat, 24 Jan 2015 15:07:53 +0000 (23:07 +0800)]
Add a few notes on the return value of uci_lookup_ptr().

While at it, use UCI_OK instead of literal integer 0 for return value of
uci_lookup_ptr().

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agocli: enhance "uci show" command on nonexistent sections and options.
Yousong Zhou [Sat, 24 Jan 2015 15:07:52 +0000 (23:07 +0800)]
cli: enhance "uci show" command on nonexistent sections and options.

When doing "uci show network.nilsection", the current behaviour is that
uci will emit a error message complaining "Entry not found", then
continue to show all content of the package network itself.  This is
couter-intuition.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agocli: properly unload package before quit.
Yousong Zhou [Sat, 24 Jan 2015 15:07:51 +0000 (23:07 +0800)]
cli: properly unload package before quit.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agotests: add test cases for showing nonexistent section and option.
Yousong Zhou [Sat, 24 Jan 2015 15:07:50 +0000 (23:07 +0800)]
tests: add test cases for showing nonexistent section and option.

Also fix the false error message about absence of uci-static.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agolua: add lua 5.2 compatibility changes
Felix Fietkau [Thu, 18 Dec 2014 15:49:16 +0000 (16:49 +0100)]
lua: add lua 5.2 compatibility changes

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 years agoallow "-" in package names
Felix Fietkau [Thu, 18 Dec 2014 14:19:47 +0000 (15:19 +0100)]
allow "-" in package names

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 years agodelta: fix outputing of delta entries occupying multiple lines.
Yousong Zhou [Tue, 16 Dec 2014 07:00:17 +0000 (15:00 +0800)]
delta: fix outputing of delta entries occupying multiple lines.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agodelta: use a table for converting between UCI_CMD_XXX and prefixes.
Yousong Zhou [Tue, 16 Dec 2014 07:00:16 +0000 (15:00 +0800)]
delta: use a table for converting between UCI_CMD_XXX and prefixes.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agodelta: preprocess delta line with uci_parse_argument().
Yousong Zhou [Tue, 16 Dec 2014 07:00:15 +0000 (15:00 +0800)]
delta: preprocess delta line with uci_parse_argument().

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agodelta: add a simple duplication check when adding delta path.
Yousong Zhou [Tue, 16 Dec 2014 07:00:14 +0000 (15:00 +0800)]
delta: add a simple duplication check when adding delta path.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agocli: fix printing option values occupying multiple lines.
Yousong Zhou [Tue, 16 Dec 2014 07:00:13 +0000 (15:00 +0800)]
cli: fix printing option values occupying multiple lines.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agotests: add test coverage for uci list related commands.
Yousong Zhou [Tue, 16 Dec 2014 07:00:12 +0000 (15:00 +0800)]
tests: add test coverage for uci list related commands.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agotests: add test coverage for `uci revert' command.
Yousong Zhou [Tue, 16 Dec 2014 07:00:11 +0000 (15:00 +0800)]
tests: add test coverage for `uci revert' command.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agotests: add test coverage for `uci batch' command.
Yousong Zhou [Tue, 16 Dec 2014 07:00:10 +0000 (15:00 +0800)]
tests: add test coverage for `uci batch' command.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agotests: add more test coverage for `uci show' command.
Yousong Zhou [Tue, 16 Dec 2014 07:00:09 +0000 (15:00 +0800)]
tests: add more test coverage for `uci show' command.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agotests: remove straying echo in 020_get.
Yousong Zhou [Tue, 16 Dec 2014 07:00:08 +0000 (15:00 +0800)]
tests: remove straying echo in 020_get.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agofile: fix error string about "unterminated XXX".
Yousong Zhou [Tue, 16 Dec 2014 07:00:07 +0000 (15:00 +0800)]
file: fix error string about "unterminated XXX".

 - Remove unreachable call to uci_parse_error().
 - Fix false claim of unterminated double quote to single quote.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agofile: fix EOF check.
Yousong Zhou [Tue, 16 Dec 2014 07:00:06 +0000 (15:00 +0800)]
file: fix EOF check.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agofile: fix use-after-free bug.
Yousong Zhou [Tue, 16 Dec 2014 07:00:05 +0000 (15:00 +0800)]
file: fix use-after-free bug.

Currently, it's possible that pointers returned by next_arg() could be
invalidated by another call to next_arg() due to uci_realloc().

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agoFix memory leaks found by using valgrind on test cases.
Yousong Zhou [Tue, 16 Dec 2014 07:00:04 +0000 (15:00 +0800)]
Fix memory leaks found by using valgrind on test cases.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
9 years agoFix a few style issues.
Yousong Zhou [Tue, 16 Dec 2014 07:00:03 +0000 (15:00 +0800)]
Fix a few style issues.

 - Remove deprecated uci-static and ucimap-example from .gitignore.
 - Minor code formatting fix.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
10 years agofix a few formatting issues
Felix Fietkau [Tue, 25 Nov 2014 10:54:09 +0000 (11:54 +0100)]
fix a few formatting issues

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agotests: use uci instead of uci-static
Felix Fietkau [Tue, 25 Nov 2014 10:50:25 +0000 (11:50 +0100)]
tests: use uci instead of uci-static

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agoAdd test coverage for multi-line option value.
Yousong Zhou [Thu, 6 Nov 2014 20:21:48 +0000 (04:21 +0800)]
Add test coverage for multi-line option value.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
10 years agoUse offset into parser buffer to avoid potential heap overflow.
Yousong Zhou [Thu, 6 Nov 2014 20:21:47 +0000 (04:21 +0800)]
Use offset into parser buffer to avoid potential heap overflow.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
10 years agoSync ref test result with current implementation.
Yousong Zhou [Thu, 6 Nov 2014 20:21:46 +0000 (04:21 +0800)]
Sync ref test result with current implementation.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
10 years agoDrop test cases for deprecated ucimap-example.
Yousong Zhou [Thu, 6 Nov 2014 20:21:45 +0000 (04:21 +0800)]
Drop test cases for deprecated ucimap-example.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
10 years agoPreserve original permissions when rewriting config files on commit
Jo-Philipp Wich [Fri, 11 Apr 2014 16:02:51 +0000 (18:02 +0200)]
Preserve original permissions when rewriting config files on commit

Patch provided by Patrick Grimm <patrick@lunatiki.de>

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
10 years agouci: fix Lua finding
Yegor Yefremov [Sun, 6 Apr 2014 19:41:32 +0000 (21:41 +0200)]
uci: fix Lua finding

If ${LUAPATH} is not quoted and Lua is not provided, then following
error occurs:

"NOT" "No such file or directory" "EQUAL" "0" "OR" "EQUAL" ""

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
10 years agofix `uci import` with not yet existing packages
Alexander Couzens [Wed, 19 Mar 2014 12:50:01 +0000 (13:50 +0100)]
fix `uci import` with not yet existing packages

uci_file_commit() tries to open and lock a package file (e.g.
/etc/config/system)
before writing into. When the package file doesn't exist, uci fails with
'Entry not found'.

10 years agoblob: add support for u64
Steven Barth [Tue, 18 Feb 2014 09:15:49 +0000 (10:15 +0100)]
blob: add support for u64

10 years agouci_blob: add an element to uci_blob_param_list to allow the tracking of validation...
John Crispin [Mon, 17 Feb 2014 12:15:17 +0000 (12:15 +0000)]
uci_blob: add an element to uci_blob_param_list to allow the tracking of validation info

Signed-off-by: John Crispin <blogic@openwrt.org>
10 years agoblob: use BLOBMSG_TYPE_STRING as a fallback type for arrays if no type was specified
Felix Fietkau [Mon, 2 Dec 2013 10:11:21 +0000 (11:11 +0100)]
blob: use BLOBMSG_TYPE_STRING as a fallback type for arrays if no type was specified

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 years agoremove ucimap-example, as ucimap is deprecated
Felix Fietkau [Mon, 2 Dec 2013 07:36:33 +0000 (08:36 +0100)]
remove ucimap-example, as ucimap is deprecated

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
11 years agoblob: allow values to be added to blobmsg using multiple different types, but suppres...
Felix Fietkau [Mon, 4 Nov 2013 15:43:49 +0000 (16:43 +0100)]
blob: allow values to be added to blobmsg using multiple different types, but suppress duplicates

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
11 years agoucimap: get rid of duplicate initialization warnings
Felix Fietkau [Tue, 29 Oct 2013 15:50:47 +0000 (16:50 +0100)]
ucimap: get rid of duplicate initialization warnings

Signed-off-by: Felix Fietkau <nbd@openwrt.org>