> "Richard L. Hamilton" <[EMAIL PROTECTED]> wrote:
> 
> > Just stumbled across
> >
> http://src.opensolaris.org/source/xref/onnv/onnv-gate/
> usr/src/cmd/cron/cron.c#1128
> >
> > Somehow, that looks less than safe to me; if fed a
> crontab where the last
> > character is a backslash (no newline), I wonder if
> that code could still be
> > guaranteed to be well-behaved.  (not that I've
> managed to make it core
> > yet over that)
> 
> A fix would be:
> 
> if (line[cursor] == '\\' && line[cursor+1] != '\n'  && line[cursor+1] != 
> '\0') {
>               cursor += 2;
>               goto again;
>       }
> 
> Jörg

Yes, you understand my concern,  However, I think your fix would fail to
advance past the backslash if it was followed by a newline or null byte.
That is not necessarily unreasonable given the subsequent code, but it's
different from current behavior.

I think that replacing

   1122 again:
   1123         while ((line[cursor] != '%') &&
   1124             (line[cursor] != '\n') &&
   1125             (line[cursor] != '\0') &&
   1126             (line[cursor] != '\\'))
   1127                 cursor++;
   1128         if (line[cursor] == '\\') {
   1129                 cursor += 2;
   1130                 goto again;
   1131         }

with

   ____         while ((line[cursor] != '%') &&
   ____             (line[cursor] != '\n') &&
   ____             (line[cursor] != '\0')) {
   ____                 if (line[cursor] != '\\')
   ____                         cursor++;
   ____                 else {
   ____                         cursor++;
   ____                         if (line[cursor]!='\n' && line[cursor]!='\0')
   ____                                 cursor++;
   ____                 }
   ____         }

would be both safe and maintain all safe current behavior, and would even
get rid of the label and goto.  (The brackets for the while block aren't 
needed, but
IMO with the if...else make it more readable.)

I don't claim that's the simplest possible way to accomplish those objectives, 
but it
seems to me to be both correct and reasonably clear.  And barring cron having to
read millions of lines at startup or when a huge crontab is changed, I doubt 
that minor
differences in efficiency matter as much as clear and correct code.
 
 
This message posted from opensolaris.org
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to