Re: [PATCH 1/2] gpg-interface: handle missing " with " gracefully in parse_ssh_output()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 01.11.21 um 09:40 schrieb Fabian Stelzer:
> On 30.10.21 19:04, René Scharfe wrote:
>> Silly bonus question: What's the purpose of the "+ 1" and "- 1", which
>> seem to cancel each other out?
>
> They do. But only for the xmemdupz. It is important for the strstr() to
> skip over already found strings (" with " could be in the principal name
> as well - multiple times even). And doing strstr(line +1, ...) can be
> problematic for the first iteration.

Ah, right.

>>  		do {
>>  			search = strstr(line, " with ");
>>  			if (search)
>>  				line = search + 1;
>>  		} while (search != NULL);

This can be shortened to:

		while ((search = strstr(line, " with ")))
			line = search + 1;

I still would have tripped over the +1 / -1, though.  Calling an rfind()
or strrstr() or find_last() function that deals with it internally
would have helped me avoid that, I think, but we don't have use for such
a thing anywhere else.

René




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux