2014-08-11 2:06 GMT+04:00 patrick keshishian <[email protected]>:
> On 8/10/14, Vadim Zhukov <[email protected]> wrote:
>> This changes the way ifconfig(8) to print lines like 'crazy "nwid',
>> i.e., containing double quotes inside the data being output.
>> At the present, such lines will be printed in the following way:
>>
>> "crazy "nwid"
>>
>> And this makes everything that tries to parse such lines go crazy
>> in their turn. I propose to force unambigious hexadecimal output
>> in this case.
>
> Caution: Slippery slope ahead!
>
> Any other "weird" characters that may confuse parsers? I see a
> bunch of networks with single-quotes in them in my area. What
> about back-slashes, back-ticks, exclamation-marks, hash-marks,
> ...?

No problem with those: they'll be a single word (here "word" means
"string without white space characters" or get quoted anyway. See,
what happens with different strings fed into print_string() now:

1. Simple ASCII word:
foo
foo

2. A few ASCII words:
foo bar
"foo bar"

3. ASCII word containing "safe" symbol:
foo&bar
foo&bar

4. A few ASCII words plus a "safe" symbol:
foo &bar
"foo &bar"

5. ASCII word with a double quote:
foo"bar
foo"bar

6. A few ASCII words with a double quote:
foo "bar
"foo "bar"

7. Non-ASCII word:
fooАБВbar
0x666f6fd090d091d0926261720a

The 1-4 and 7 could be easily parsed, e.g., by regex. But 5 and 6
can't be. My patch fixes this situation, changing them to 0x form,
too.

There is another problem, with 0x.* strings being undistinguishable:
is it an original value, or was it translated by ifconfig? But IMHO it
should be discussed and dealed separately. I could be wrong, though.
:)

>> Objections/okays?
>> --
>> WBR,
>>   Vadim Zhukov
>>
>>
>> Index: ifconfig.c
>> ===================================================================
>> RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
>> retrieving revision 1.287
>> diff -u -p -r1.287 ifconfig.c
>> --- ifconfig.c        12 Jul 2014 19:58:17 -0000      1.287
>> +++ ifconfig.c        10 Aug 2014 21:11:03 -0000
>> @@ -1499,8 +1499,8 @@ print_string(const u_int8_t *buf, int le
>>
>>       if (len < 2 || buf[0] != '0' || tolower(buf[1]) != 'x') {
>>               for (; i < len; i++) {
>> -                     /* Only print 7-bit ASCII keys */
>> -                     if (buf[i] & 0x80 || !isprint(buf[i]))
>> +                     /* Only print 7-bit ASCII keys, excluding double quote 
>> */
>> +                     if (buf[i] & 0x80 || !isprint(buf[i]) || buf[i] == '"')
>>                               break;
>>                       if (isspace(buf[i]))
>>                               hasspc++;
>>
>>

--
  WBR,
  Vadim Zhukov

Reply via email to