+2012-04-23 Keith Marshall <keithmarshall@users.sourceforge.net>
+
+ Fix MinGW-Bug #3520488
+
+ * src/pkgexec.cpp (action_code): Check for, and reject NULL pointer
+ passed as action request string; also reject ambiguous abbreviations.
+
+ * src/climain.cpp (climain): Discriminate between NULL pointer and
+ other forms of invalid action keyword matching failures.
+
2012-04-16 Keith Marshall <keithmarshall@users.sourceforge.net>
mingw-get-0.5-beta-20120416-1 released.
*/
int action = action_code( *argv );
if( action < 0 )
- /*
- * The specified action keyword was invalid;
- * force an abort through a DMH_FATAL notification...
+ {
+ /* No valid action keyword was found; force an abort
+ * through an appropriate DMH_FATAL notification...
*/
- dmh_notify( DMH_FATAL, "%s: unknown action keyword\n", *argv );
+ if( *argv == NULL )
+ /*
+ * ...viz. the user didn't specify any argument, which
+ * could have been interpreted as an action keyword.
+ */
+ dmh_notify( DMH_FATAL, "no action specified\n" );
+
+ else
+ /* ...or, the specified action keyword was invalid.
+ */
+ dmh_notify( DMH_FATAL, "%s: unknown action keyword\n", *argv );
+ }
/* If we get to here, then the specified action identifies a
* valid operation; load the package database, according to the
/* Match an action keyword specified on the command line
* to an entry from the above list...
*/
- int lencode = strlen( request );
-
- int index;
- for( index = 0; index < end_of_actions; index++ )
+ if( request != NULL )
{
- /* Try all defined keywords in turn, until we find a match
- * or we run out of definitions...
- */
- if( strncmp( request, action_name( index ), lencode ) == 0 )
+ int lencode = strlen( request );
+
+ int index, retval, matched;
+ for( index = matched = 0; index < end_of_actions; index++ )
+ {
+ /* Try all defined keywords in turn, until we run out
+ * of definitions.
+ */
+ if( (strncmp( request, action_name( index ), lencode ) == 0)
+ /*
+ * When we find a match, and it is the first...
+ */
+ && (++matched == 1) )
+ /*
+ * ...then we record as the probable index to return.
+ */
+ retval = index;
+ }
+ if( matched > 1 )
/*
- * for a successful match...
- * immediately return the associated action code index.
+ * We matched more than one valid keyword; reject them all.
*/
- return index;
+ dmh_notify( DMH_ERROR, "%s: action keyword is ambiguous\n", request );
+
+ else if( matched == 1 )
+ /*
+ * We matched exactly one keyword; return its index value.
+ */
+ return retval;
}
-
- /* If we get to here, the specified keyword was not matched;
+ /* If we get to here, the specified keyword was not uniquely matched;
* signal this, by returning -1.
*/
return -1;