From: Erik van der Kouwe Date: Thu, 21 Jan 2010 10:16:05 +0000 (+0000) Subject: Fix parameter parsing in cut X-Git-Tag: v3.1.6~54 X-Git-Url: http://zhaoyanbai.com/repos/man.dnssec-verify.html?a=commitdiff_plain;h=0bc2aad4af343e418228c1aab4273a92d938b57e;p=minix.git Fix parameter parsing in cut --- diff --git a/LICENSE b/LICENSE index 9cbf4712c..a119efa5f 100644 --- a/LICENSE +++ b/LICENSE @@ -50,3 +50,13 @@ observe the conditions of the GPL with respect to this software. As clearly stated in Article 2 of the GPL, when GPL and nonGPL software are distributed together on the same medium, this aggregation does not cause the license of either part to apply to the other part. + + +Acknowledgements + +This product includes software developed by the University of +California, Berkeley and its contributors. + +This product includes software developed by Softweyr LLC, the +University of California, Berkeley, and its contributors. + diff --git a/commands/simple/cut.c b/commands/simple/cut.c index 79d57f830..d3641cac1 100644 --- a/commands/simple/cut.c +++ b/commands/simple/cut.c @@ -134,7 +134,10 @@ void get_args() args[arg_ptr] = 10 * args[arg_ptr] + line[i++] - '0'; if (!args[arg_ptr]) cuterror(POSITION_ERROR); arg_ptr++; + } else if (line[i] != '-') { + cuterror(SYNTAX_ERROR); } + if (line[i] == '-') { arg_ptr |= 1; i++; @@ -208,6 +211,7 @@ int main(argc, argv) int argc; char *argv[]; { + char *linearg; int i = 1; int numberFilenames = 0; name = argv[0]; @@ -220,22 +224,29 @@ char *argv[]; case 'd': if (mode == OPTIONC || mode == OPTIONB) warn(DELIMITER_NOT_APPLICABLE, "d"); - delim = argv[i++][0]; + delim = argv[i - 1][2] ? + argv[i - 1][2] : argv[i++][0]; break; case 'f': - sprintf(line, "%s", argv[i++]); + linearg = argv[i - 1][2] ? + (argv[i - 1] + 2) : argv[i++]; + sprintf(line, "%s", linearg); if (mode == OPTIONC || mode == OPTIONB) warn(OVERRIDING_PREVIOUS_MODE, "f"); mode = OPTIONF; break; case 'b': - sprintf(line, "%s", argv[i++]); + linearg = argv[i - 1][2] ? + (argv[i - 1] + 2) : argv[i++]; + sprintf(line, "%s", linearg); if (mode == OPTIONF || mode == OPTIONC) warn(OVERRIDING_PREVIOUS_MODE, "b"); mode = OPTIONB; break; case 'c': - sprintf(line, "%s", argv[i++]); + linearg = argv[i - 1][2] ? + (argv[i - 1] + 2) : argv[i++]; + sprintf(line, "%s", linearg); if (mode == OPTIONF || mode == OPTIONB) warn(OVERRIDING_PREVIOUS_MODE, "c"); mode = OPTIONC; @@ -281,7 +292,7 @@ char *argv[]; case 'f': case 'c': case 'b': - case 'd': i += 2; break; + case 'd': i += argv[i][2] ? 1 : 2; break; case 'n': case 'i': case 's': i++; break; diff --git a/include/time.h b/include/time.h index e17c42f4e..e013dd180 100644 --- a/include/time.h +++ b/include/time.h @@ -59,6 +59,8 @@ _PROTOTYPE( char *asctime, (const struct tm *_timeptr) ); _PROTOTYPE( char *ctime, (const time_t *_timer) ); _PROTOTYPE( struct tm *gmtime, (const time_t *_timer) ); _PROTOTYPE( struct tm *localtime, (const time_t *_timer) ); +_PROTOTYPE( struct tm *localtime_r, (const time_t *const timep, + struct tm *tmp) ); _PROTOTYPE( size_t strftime, (char *_s, size_t _max, const char *_fmt, const struct tm *_timep) );