diff --git a/apps/cli/Makefile.in b/apps/cli/Makefile.in index 5529d429..b6763b9a 100644 --- a/apps/cli/Makefile.in +++ b/apps/cli/Makefile.in @@ -51,8 +51,9 @@ SH_SUFFIX = @SH_SUFFIX@ LIBSTATIC_SUFFIX = @LIBSTATIC_SUFFIX@ INSTALLFLAGS = @INSTALLFLAGS@ LDFLAGS = @LDFLAGS@ -ifeq ($(LINKAGE),dynamic) -LDFLAGS += -rdynamic -L. # -rdynamic for using -ldl +ifneq ($(LINKAGE),dynamic) + # -rdynamic for using -ldl +LDFLAGS += -rdynamic endif prefix = @prefix@ @@ -179,13 +180,19 @@ test: $(MYLIBSTATIC) endif $(CC) $(INCLUDES) $(LDFLAGS) -L . $^ $(LIBS) -o $@ +# Note1: static linking of clixon_cli must have: +# 1) -rdynamic +# 2) $(APPOBJ) +# Note2: LIBDEPS is just a mechanism to ensure libclixon.so is built +$(APPL): $(APPOBJ) $(LIBDEPS) ifeq ($(LINKAGE),dynamic) $(APPL): $(MYLIBDYNAMIC) + echo "LIBS:$(LIBS)" + $(CC) $(LDFLAGS) $(APPOBJ) $(EXTRAS) $(CLIGEN_LIB) $(LIBS) -L. $< -o $@ else -$(APPL): $(MYLIBSTATIC) +$(APPL): $(LIBOBJ) + $(CC) $(LDFLAGS) $(APPOBJ) $(EXTRAS) $(LIBOBJ) $(CLIGEN_LIB) $(LIBS) -o $@ endif -$(APPL): $(APPOBJ) $(LIBDEPS) - $(CC) $(LDFLAGS) $(EXTRAS) -L. $^ $(CLIGEN_LIB) $(LIBS) -o $@ $(MYLIBDYNAMIC) : $(LIBOBJ) $(LIBDEPS) ifeq ($(HOST_VENDOR),apple) diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index 270e833b..d65a150a 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -1310,7 +1310,7 @@ cli_help(clicon_handle h, cvec *vars, cvec *argv) cligen_handle ch = cli_cligen(h); parse_tree *pt; - pt = cligen_ph_active_get(ch); + pt = cligen_pt_active_get(ch); return cligen_help(ch, stdout, pt); } diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c index 756658c4..0264490e 100644 --- a/apps/cli/cli_main.c +++ b/apps/cli/cli_main.c @@ -575,6 +575,10 @@ main(int argc, argc -= optind; argv += optind; +#ifdef __AFL_HAVE_MANUAL_CONTROL + __AFL_INIT(); +#endif + /* Access the remaining argv/argc options (after --) w clicon-argv_get() */ clicon_argv_set(h, argv0, argc, argv); @@ -754,8 +758,9 @@ main(int argc, } /* Go into event-loop unless -1 command-line */ - if (!once) + if (!once){ retval = cli_interactive(h); + } else retval = 0; done: diff --git a/apps/cli/cli_plugin.c b/apps/cli/cli_plugin.c index 0930438b..89f9294f 100644 --- a/apps/cli/cli_plugin.c +++ b/apps/cli/cli_plugin.c @@ -523,8 +523,10 @@ cli_handler_err(FILE *f) } /*! Evaluate a matched command - * @param[in] h Clicon handle - * @param[in] cmd The command string + * @param[in] h Clicon handle + * @param[in] cmd The command string + * @param[in] match_obj + * @param[in] cvv * @retval int If there is a callback, the return value of the callback is returned, * @retval 0 otherwise */ @@ -603,13 +605,13 @@ clicon_parse(clicon_handle h, } if (csm != NULL){ modename0 = NULL; - if ((pt = cligen_ph_active_get(cli_cligen(h))) != NULL) + if ((pt = cligen_pt_active_get(cli_cligen(h))) != NULL) modename0 = pt_name_get(pt); if (cligen_ph_active_set(cli_cligen(h), modename) < 0){ fprintf(stderr, "No such parse-tree registered: %s\n", modename); goto done; } - if ((pt = cligen_ph_active_get(cli_cligen(h))) == NULL){ + if ((pt = cligen_pt_active_get(cli_cligen(h))) == NULL){ fprintf(stderr, "No such parse-tree registered: %s\n", modename); goto done; } diff --git a/apps/netconf/netconf_main.c b/apps/netconf/netconf_main.c index 4a574529..7add4dfd 100644 --- a/apps/netconf/netconf_main.c +++ b/apps/netconf/netconf_main.c @@ -876,6 +876,10 @@ main(int argc, if (send_hello(h, 1, id) < 0) goto done; } +#ifdef __AFL_HAVE_MANUAL_CONTROL + /* American fuzzy loop deferred init, see CLICON_NETCONF_HELLO_OPTIONAL=true, see a speedup of x10 */ + __AFL_INIT(); +#endif if (clixon_event_reg_fd(0, netconf_input_cb, h, "netconf socket") < 0) goto done; if (dbg) @@ -887,6 +891,7 @@ main(int argc, if (clixon_event_reg_timeout(t, timeout_fn, NULL, "timeout") < 0) goto done; } + if (clixon_event_loop(h) < 0) goto done; retval = 0; diff --git a/example/main/Makefile.in b/example/main/Makefile.in index 514b00db..5411a195 100644 --- a/example/main/Makefile.in +++ b/example/main/Makefile.in @@ -145,10 +145,9 @@ $(RESTCONF_PLUGIN): $(RESTCONF_OBJ) ifeq ($(LINKAGE),dynamic) $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $^ -lclixon -lclixon_restconf else -# XXX need to add -L ../../apps/restconf otherwise get undefined: -# plugin_load_one file:/usr/local/lib/example/restconf/example_restconf.so function:clixon_plugin_init -# plugin_load_one: 338: Plugins: dlopen(/usr/local/lib/example/restconf/example_restconf.so): /usr/local/lib/libclixon_restconf.so.5: undefined symbol: api_return_err - $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $^ -lclixon -L ../../apps/restconf/ -lclixon_restconf +# Linkage -static: + $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $^ -lclixon -L ../../apps/restconf/ -lclixon_restconf +# $(CC) -Wall -shared $(LDFLAGS) -o $@ -lc $^ -lclixon -lclixon_restconf endif SRC = $(BE_SRC) $(BE2_SRC) $(CLI_SRC) $(NETCONF_SRC) diff --git a/fuzz/cli/README.md b/fuzz/cli/README.md index 107402fc..a25c248a 100644 --- a/fuzz/cli/README.md +++ b/fuzz/cli/README.md @@ -2,8 +2,6 @@ This dir contains code for fuzzing clixon cli. -Note: cli plugins do not work. - ## Prereqs Install AFL, see [..](..) @@ -12,7 +10,7 @@ Build and install a clixon system (in particular the backend, the CLI will be re Build and install CLIgen statically: ``` - CC=/usr/bin/afl-clang-fast LINKAGE=static INSTALLFLAGS="" ./configure + ./configure LINKAGE=static INSTALLFLAGS="" CC=/usr/bin/afl-clang-fast ``` ## Build diff --git a/lib/src/clixon_xpath_parse.y b/lib/src/clixon_xpath_parse.y index 5619344a..55f3d119 100644 --- a/lib/src/clixon_xpath_parse.y +++ b/lib/src/clixon_xpath_parse.y @@ -384,31 +384,31 @@ start : expr X_EOF { _XPY->xpy_top=$1;_PARSE_DEBUG("start->expr"); | locationpath X_EOF { _XPY->xpy_top=$1;_PARSE_DEBUG("start->locationpath"); YYACCEPT; } ; -expr : expr LOGOP andexpr { $$=xp_new(XP_EXP,$2,NULL,NULL,NULL,$1, $3);_PARSE_DEBUG("expr->expr or andexpr"); } +expr : expr LOGOP andexpr { $$=xp_new(XP_EXP,$2,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$; _PARSE_DEBUG("expr->expr or andexpr"); } | andexpr { $$=xp_new(XP_EXP,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("expr-> andexpr"); } ; -andexpr : andexpr LOGOP relexpr { $$=xp_new(XP_AND,$2,NULL,NULL,NULL,$1, $3);_PARSE_DEBUG("andexpr-> andexpr and relexpr"); } - | relexpr { $$=xp_new(XP_AND,A_NAN,NULL,NULL,NULL,$1, NULL);_PARSE_DEBUG("andexpr-> relexpr"); } +andexpr : andexpr LOGOP relexpr { $$=xp_new(XP_AND,$2,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("andexpr-> andexpr and relexpr"); } + | relexpr { $$=xp_new(XP_AND,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("andexpr-> relexpr"); } ; -relexpr : relexpr RELOP addexpr { $$=xp_new(XP_RELEX,$2,NULL,NULL,NULL,$1, $3);_PARSE_DEBUG("relexpr-> relexpr relop addexpr"); } - | addexpr { $$=xp_new(XP_RELEX,A_NAN,NULL,NULL,NULL,$1, NULL);_PARSE_DEBUG("relexpr-> addexpr"); } +relexpr : relexpr RELOP addexpr { $$=xp_new(XP_RELEX,$2,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("relexpr-> relexpr relop addexpr"); } + | addexpr { $$=xp_new(XP_RELEX,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("relexpr-> addexpr"); } ; -addexpr : addexpr ADDOP unionexpr { $$=xp_new(XP_ADD,$2,NULL,NULL,NULL,$1, $3);_PARSE_DEBUG("addexpr-> addexpr ADDOP unionexpr"); } - | unionexpr { $$=xp_new(XP_ADD,A_NAN,NULL,NULL,NULL,$1, NULL);_PARSE_DEBUG("addexpr-> unionexpr"); } +addexpr : addexpr ADDOP unionexpr { $$=xp_new(XP_ADD,$2,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("addexpr-> addexpr ADDOP unionexpr"); } + | unionexpr { $$=xp_new(XP_ADD,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("addexpr-> unionexpr"); } ; /* node-set */ -unionexpr : unionexpr '|' pathexpr { $$=xp_new(XP_UNION,XO_UNION,NULL,NULL,NULL,$1, $3);_PARSE_DEBUG("unionexpr-> unionexpr | pathexpr"); } - | pathexpr { $$=xp_new(XP_UNION,A_NAN,NULL,NULL,NULL,$1, NULL);_PARSE_DEBUG("unionexpr-> pathexpr"); } +unionexpr : unionexpr '|' pathexpr { $$=xp_new(XP_UNION,XO_UNION,NULL,NULL,NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("unionexpr-> unionexpr | pathexpr"); } + | pathexpr { $$=xp_new(XP_UNION,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("unionexpr-> pathexpr"); } ; -pathexpr : locationpath { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,NULL,NULL,$1, NULL);_PARSE_DEBUG("pathexpr-> locationpath"); } - | filterexpr { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,NULL,NULL,$1, NULL);_PARSE_DEBUG("pathexpr-> filterexpr"); } - | filterexpr '/' rellocpath { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,strdup("/"),NULL,$1, $3);_PARSE_DEBUG("pathexpr-> filterexpr / rellocpath"); } - | filterexpr DOUBLESLASH rellocpath { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,strdup("//"),NULL,$1, $3);_PARSE_DEBUG("pathexpr-> filterexpr // rellocpath"); } +pathexpr : locationpath { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("pathexpr-> locationpath"); } + | filterexpr { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,NULL,NULL,$1, NULL);_XPY->xpy_top=$$;_PARSE_DEBUG("pathexpr-> filterexpr"); } + | filterexpr '/' rellocpath { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,strdup("/"),NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("pathexpr-> filterexpr / rellocpath"); } + | filterexpr DOUBLESLASH rellocpath { $$=xp_new(XP_PATHEXPR,A_NAN,NULL,strdup("//"),NULL,$1, $3);_XPY->xpy_top=$$;_PARSE_DEBUG("pathexpr-> filterexpr // rellocpath"); } ; filterexpr : primaryexpr { $$=xp_new(XP_FILTEREXPR,A_NAN,NULL,NULL,NULL,$1, NULL);_PARSE_DEBUG("filterexpr-> primaryexpr"); } diff --git a/test/cicd/coverage.sh b/test/cicd/coverage.sh index fe90e998..8a87b6c2 100755 --- a/test/cicd/coverage.sh +++ b/test/cicd/coverage.sh @@ -15,7 +15,7 @@ TOKEN=$1 # Configure (clixon) #CFLAGS="-g -Wall" INSTALLFLAGS="" ./configure #sudo ldconfig -LDFLAGS=-coverage LINKAGE=static CFLAGS="-g -Wall -coverage" INSTALLFLAGS="" ./configure +./configure LDFLAGS=-coverage LINKAGE=static CFLAGS="-g -Wall -coverage" INSTALLFLAGS="" # Build make clean diff --git a/test/config.sh.in b/test/config.sh.in index 5ee28787..358005a8 100755 --- a/test/config.sh.in +++ b/test/config.sh.in @@ -77,4 +77,4 @@ CERTKEYLEN=2048 # Linking: static or dynamic LINKAGE=@LINKAGE@ SH_SUFFIX=@SH_SUFFIX@ - +LIBSTATIC_SUFFIX=@LIBSTATIC_SUFFIX@ diff --git a/test/test_install.sh b/test/test_install.sh index 12c43679..0ec82824 100755 --- a/test/test_install.sh +++ b/test/test_install.sh @@ -10,8 +10,10 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi # Check for soft links for .so files in case of dynamic linkage, but .a files f static linking if [ ${LINKAGE} = static ]; then LIBOPT=-f + SUFFIX=${LIBSTATIC_SUFFIX} else LIBOPT=-h + SUFFIX=${SH_SUFFIX} fi new "Set up installdir $dir" @@ -32,18 +34,18 @@ new "Check installed files clixon-config" if [ ! -f $dir/usr/local/share/clixon/clixon-config* ]; then err $dir/usr/local/share/clixon/clixon-config* fi -new "Check installed files libclixon${SH_SUFFIX}" +new "Check installed files libclixon${SUFFIX}" # Check both /usr/local/lib and /usr/lib # This is a problem on some platforms that dont have /usr/local/ in LD_LIBRARY_PATH -if [ ! ${LIBOPT} $dir/usr/local/lib/libclixon${SH_SUFFIX} ]; then - if [ ! ${LIBOPT} $dir/usr/lib/libclixon${SH_SUFFIX} ]; then - err $dir/usr/local/lib/libclixon${SH_SUFFIX} +if [ ! ${LIBOPT} $dir/usr/local/lib/libclixon${SUFFIX} ]; then + if [ ! ${LIBOPT} $dir/usr/lib/libclixon${SUFFIX} ]; then + err $dir/usr/local/lib/libclixon${SUFFIX} fi fi -new "Check installed files libclixon_backend${SH_SUFFIX}" -if [ ! ${LIBOPT} $dir/usr/local/lib/libclixon_backend${SH_SUFFIX} ]; then - if [ ! ${LIBOPT} $dir/usr/lib/libclixon_backend${SH_SUFFIX} ]; then - err $dir/usr/local/lib/libclixon_backend${SH_SUFFIX} +new "Check installed files libclixon_backend${SUFFIX}" +if [ ! ${LIBOPT} $dir/usr/local/lib/libclixon_backend${SUFFIX} ]; then + if [ ! ${LIBOPT} $dir/usr/lib/libclixon_backend${SUFFIX} ]; then + err $dir/usr/local/lib/libclixon_backend${SUFFIX} fi fi