[RFC,1/7] apps: common: Fix flipped error condition
diff mbox series

Message ID 20250314202943.112109-2-mzamazal@redhat.com
State New
Headers show
Series
  • Support different outputs for cam streams
Related show

Commit Message

Milan Zamazal March 14, 2025, 8:29 p.m. UTC
When OptionsParser::childOption encounters an error, it returns nullptr
and the corresponding option.  The check for a nested parent checks for
an error erroneously, leading not only to a wrong behaviour in case
there's no error but also to a segmentation error in case of error due
to `options' being set to nullptr and accessed later.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 src/apps/common/options.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Barnabás Pőcze Nov. 10, 2026, 8:23 a.m. UTC | #1
Hu

2025. 03. 14. 21:29 keltezéssel, Milan Zamazal írta:
> When OptionsParser::childOption encounters an error, it returns nullptr
> and the corresponding option.  The check for a nested parent checks for
> an error erroneously, leading not only to a wrong behaviour in case
> there's no error but also to a segmentation error in case of error due
> to `options' being set to nullptr and accessed later.
> 
> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
> ---

This can only happen if there are at least 3 levels of options, no?
And the current max is 2 levels, right?

Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>


>   src/apps/common/options.cpp | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/apps/common/options.cpp b/src/apps/common/options.cpp
> index cae193cc..29a5d9c7 100644
> --- a/src/apps/common/options.cpp
> +++ b/src/apps/common/options.cpp
> @@ -1095,7 +1095,7 @@ OptionsParser::childOption(const Option *parent, Options *options)
>   		std::tie(options, error) = childOption(parent->parent, options);
>   
>   		/* Propagate the error all the way back up the call stack. */
> -		if (!error)
> +		if (error)
>   			return { options, error };
>   	}
>
Milan Zamazal Nov. 12, 2026, 1:48 p.m. UTC | #2
Hi Barnabás,

thank you for review.

Barnabás Pőcze <barnabas.pocze@ideasonboard.com> writes:

> Hu
>
> 2025. 03. 14. 21:29 keltezéssel, Milan Zamazal írta:
>> When OptionsParser::childOption encounters an error, it returns nullptr
>> and the corresponding option.  The check for a nested parent checks for
>> an error erroneously, leading not only to a wrong behaviour in case
>> there's no error but also to a segmentation error in case of error due
>> to `options' being set to nullptr and accessed later.
>> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
>> ---
>
> This can only happen if there are at least 3 levels of options, no?
> And the current max is 2 levels, right?

The current max is probably 2, but with the followup patches in the
series, it becomes 3: --camera ... --stream ... <stream output options>.
IIRC I've experienced the crash.

>
> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
>
>
>>   src/apps/common/options.cpp | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>> diff --git a/src/apps/common/options.cpp b/src/apps/common/options.cpp
>> index cae193cc..29a5d9c7 100644
>> --- a/src/apps/common/options.cpp
>> +++ b/src/apps/common/options.cpp
>> @@ -1095,7 +1095,7 @@ OptionsParser::childOption(const Option *parent, Options *options)
>>   		std::tie(options, error) = childOption(parent->parent, options);
>>     		/* Propagate the error all the way back up the call stack. */
>> -		if (!error)
>> +		if (error)
>>   			return { options, error };
>>   	}
>>

Patch
diff mbox series

diff --git a/src/apps/common/options.cpp b/src/apps/common/options.cpp
index cae193cc..29a5d9c7 100644
--- a/src/apps/common/options.cpp
+++ b/src/apps/common/options.cpp
@@ -1095,7 +1095,7 @@  OptionsParser::childOption(const Option *parent, Options *options)
 		std::tie(options, error) = childOption(parent->parent, options);
 
 		/* Propagate the error all the way back up the call stack. */
-		if (!error)
+		if (error)
 			return { options, error };
 	}