Permalink
Browse files

Verify device input format and allow trailing back slash

  • Loading branch information...
kimwolk committed Jul 22, 2011
1 parent 48e8e6f commit fdb8baf8723452c87aba6c61b379440be9a9e20a
Showing with 26 additions and 0 deletions.
  1. +26 −0 src/COptions.h
View
@@ -164,6 +164,14 @@ class COptions
throw new CParseOptionsException(TEXT("Missing required arguments."));
}
+ options._device.TrimRight(TEXT('\\'));
+ if (!IsValidDevice(options._device))
+ {
+ CString message("Device format is incorrect. Device = ");
+ message.Append(options._device);
+ throw new CParseOptionsException(message);
+ }
+
return options;
}
@@ -182,6 +190,24 @@ class COptions
return arg.Mid(index + 1);
}
+ static bool IsValidDevice(const CString& arg)
+ {
+ CString temp(arg);
+ temp.MakeLower();
+
+ if (2 != temp.GetLength() || TEXT(':') != temp.GetAt(1))
+ {
+ return false;
+ }
+
+ TCHAR driveLetter = temp.GetAt(0);
+ if (driveLetter > TEXT('z') || driveLetter < TEXT('a'))
+ {
+ return false;
+ }
+
+ return true;
+ }
static CString NormalizePath(LPCTSTR path)
{
int length = MAX_PATH;

0 comments on commit fdb8baf

Please sign in to comment.