-
Notifications
You must be signed in to change notification settings - Fork 123
gopts: validation of CLI options not working #4029
Comments
@kodebach can this be solved by changing the placement of gopts or is this a bigger problem? |
Did you mount the spec and then
This would be a bug in
That's the default error handler, you can set a different one with |
@kodebach Thanks for your comment! I think your last paragraph was accidentally cut off? It ends with
Adding elektraFatalErrorHandler()Ah, thanks for the hint! I've now added static void onFatalError(ElektraError * error) {
fprintf(stderr, "An error occured during an Elektra operation: %s \n", elektraErrorDescription(error));
elektraErrorReset(&error);
exit(EXIT_FAILURE);
} and put That changes the actual behavior: Class 2: wrong typeNow E.g. for E.g. for That is still not the expected behavior, because these problems should already be detected during Class 3: validation errors reported by check/* pluginsThe behavior is unchanged. However, I made a mistake in my original report. The application only crashes for illegal enum or boolean values. So providing wrong values for these 2 types is actually error class For other E.g.
Mountpoints, loaded plugins
Yes, but I did forgot to document it in my report above :). I've now added step 5. above. After step 5. the following output occurs for: kdb mount:
kdb ls system:/elektra/mountpoints/
Summary
|
Oh sorry, it should read: "I'm pretty sure that the
No that's mostly normal with Honestly, I have no idea what is going on here. The errors look like I'll look into this myself and report back, when I know more. |
I looked into this and discovered - by reading the code and debugging - that:
c.f. libelektra/src/plugins/range/range.c Lines 468 to 488 in 6701d9e
|
Yes, I'm pretty sure this is the cause. I didn't immediately suggest it, because I thought that at least
I have advocated for this multiple times, because it is also a problem, if you modify the config file manually (which will be quite common for some applications). However, until now it seemed I'm the only one that was in favour of enforcing this. Now that we have a second (more immediate) use-case, we can probably all agree that all validation plugins should also do validation during
I don't see any other option, since |
I see, thank you!
@markus2330: What do you think about adding validation to
elektraPLUGINNAMEGet() ? Are there sensible alternatives?
…On 2021-09-13 21:53, kodebach wrote:
> Could this be the cause?
Yes, I'm pretty sure this is the cause. I didn't immediately suggest
it, because I thought that at least type also does its validation
during kdbGet.
> Would a sensible fix be, to have the check/* plugins execute the
> same validation during elektraPLUGINNAMEGet() which is performed
> during elektraPLUGINNAMESet()?
I have advocated for this multiple times, because it is also a
problem, if you modify the config file manually (which will be quite
common for some applications). However, until now it seemed I'm the
only one that was in favour of enforcing this.
> If not, do you have a suggestion for a fix?
I don't see any other option, since proc:/ should be ignored during
kdbSet. It doesn't make sense to store proc:/ keys anywhere. They are
per definition only relevant to the current process.
--
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub [1], or unsubscribe
[2].
Triage notifications on the go with GitHub Mobile for iOS [3] or
Android [4]. [ { ***@***.***": "http://schema.org", ***@***.***":
"EmailMessage", "potentialAction": { ***@***.***": "ViewAction", "target":
"#4029 (comment)",
"url":
"#4029 (comment)",
"name": "View Issue" }, "description": "View this Issue on GitHub",
"publisher": { ***@***.***": "Organization", "name": "GitHub", "url":
"https://github.com" } } ]
Links:
------
[1]
#4029 (comment)
[2]
https://github.com/notifications/unsubscribe-auth/AOX4AP4H6YPZWAULYC3RVELUBZJD3ANCNFSM5DZSEMBA
[3]
https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675
[4]
https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub
|
Some If we decide to execute their validation during E.g. |
Note: I fixed a typo in #4029 (comment). The value of |
I've split this up in 3 issues, please let's continue the discussion there:
|
Can we close this issue then? |
Yes, good idea! |
This issue is currently WIP.When using the HL API and the gopts plugin, CLI options passed to the application are not validated.
3 classes of validation errors
The following three are not detected:
Depending on the causes - which are yet to be identified - this issue should probably be split up into individual issues.
Steps to Reproduce the Problem
Execute the steps below which follow the tutorial High-level API (with code-generation).
Create file test.ini with content:
Execute
kdb gen -F ni=test.ini highlevel "/sw/example/myapp/#0/current" conf
Create file myapp.c with content:
cc -g -O0 myapp.c conf.c `pkg-config --cflags --libs elektra-codegen` -I. -o myapp -Wl,-rpath `pkg-config --variable=libdir elektra-codegen`
conf.mount.sh
:$ APP_PATH=`pwd`/myapp sh conf.mount.sh
Expected vs. actual results
kdb set - works
When
kdb set
is used all three classes of validation errors are properly detected. No examples here for sake of brevity.CLI options - don't work
When the keys are set by passing CLI options to
myapp
, the validation errors are not detected. The actual behavior depends on the class of the error.Class 1: missing argument
./myapp --mb
(--mb can be replaced by any other option, e.g. --me)Expected:
loadConfiguration ()
fails with error message "option --mb requires an argument!"Actual:
Missing value ignored, default value applied.
Class 2: wrong type
./myapp --mb notabool
./myapp --mfcr notafloat
./myapp --muscr notanunsignedshort
Expected:
loadConfiguration ()
fails with error message "type of OPTION wrong"Actual:
Application crashes within
elektraGetMyboolean()
(or the other elektraGet...()s) without an error message. Exit code is -1.Class 3: validation errors reported by check/* plugins
The check/* plugins seem not to be executed. Their validation is not executed.
./myapp --me illegalenumvalue
./myapp --mfcr 99.0
./myapp --mscd notaiso8601date
./myapp --mscv notthestring-aaa
./myapp --muscr 999
Expected:
loadConfiguration ()
fails with error message "Validation error for OPTION, reason: ..."Actual:
Application crashes within
elektraGetMyenum()
(or the other elektraGet...()s) without an error message. Exit code is -1.System Information
The text was updated successfully, but these errors were encountered: