~sircmpwn/himitsu-devel

1

Re: [PATCH himitsu] himitsud: query: close prompter if decrypt but no matches

Details
Message ID
<CTMFZ7ZEYSEN.2NBGPLY9CB8WZ@xps>
DKIM signature
missing
Download raw message
On Mon Jun 26, 2023 at 2:43 PM CST, Armin Preiml wrote:
> > @@ -190,10 +190,11 @@ fn exec_query(serv: *server, client: *client, args: []str) (void | cmderror) = {
> >  			writefmt(client, "error Failed to unlock");
> >  			return;
> >  		};
> > -		if (!decrypt) {
> > +		if (decrypt) {
> > +			prompter = new;
> > +		} else {
> >  			prompt::close(&new)?;
> >  		};
> > -		prompter = new;
> >  	};
> >  
> >  	const q = query::parse_items(cmd.args)?;
> > @@ -236,6 +237,8 @@ fn exec_query(serv: *server, client: *client, args: []str) (void | cmderror) = {
> >  			writefmt(client, "error User declined");
> >  			return;
> >  		};
> > +	} else if (prompter is prompt::prompter) {
> > +		prompt::close(&(prompter: prompt::prompter))?;
> >  	};
>
> It would be safer to use a defer after defining prompter like:
>
> defer if (prompter is prompt::prompter) promt::close...
>
> This would make the code a little less complex.

The challenge here is that prompt::wait also closes the prompter, so if
the prompter is created for unlocking and futher reused for decrypting,
the prompter would be already closed by prompt::wait.

We can add a check in defer for that case, but I think it will be more
complex instead than this patch.

Re: [PATCH himitsu] himitsud: query: close prompter if decrypt but no matches

Details
Message ID
<5797e3f4-a2ce-c4b1-e16f-d2837c81f568@strohwolke.at>
In-Reply-To
<CTMFZ7ZEYSEN.2NBGPLY9CB8WZ@xps> (view parent)
DKIM signature
missing
Download raw message
On 6/26/23 10:36, Pinghao Wu wrote:
>>>   	const q = query::parse_items(cmd.args)?;
>>> @@ -236,6 +237,8 @@ fn exec_query(serv: *server, client: *client, args: []str) (void | cmderror) = {
>>>   			writefmt(client, "error User declined");
>>>   			return;
>>>   		};
>>> +	} else if (prompter is prompt::prompter) {
>>> +		prompt::close(&(prompter: prompt::prompter))?;
>>>   	};
>>
>> It would be safer to use a defer after defining prompter like:
>>
>> defer if (prompter is prompt::prompter) promt::close...
>>
>> This would make the code a little less complex.
> 
> The challenge here is that prompt::wait also closes the prompter, so if
> the prompter is created for unlocking and futher reused for decrypting,
> the prompter would be already closed by prompt::wait.
> 
> We can add a check in defer for that case, but I think it will be more
> complex instead than this patch.

What about setting prompt to void after wait?
Reply to thread Export thread (mbox)