Make hexchar() return -1 on invalid input instead of calling fatalx().

Callers used to check that the string was hex before calling hexchar().
Now callers must check for a -1 return value instead.
This commit is contained in:
Todd C. Miller
2014-03-26 13:50:51 -06:00
parent 2220f55aef
commit 9ff3b1b570
3 changed files with 13 additions and 13 deletions

View File

@@ -21,8 +21,11 @@
#include "missing.h"
#include "sudo_debug.h"
#include "fatal.h"
/*
* Converts a two-byte hex string to decimal.
* Returns the decimal value or -1 for invalid input.
*/
int
hexchar(const char *s)
{
@@ -87,8 +90,8 @@ hexchar(const char *s)
result[i] = 15;
break;
default:
/* Should not happen. */
fatalx("internal error, \\x%s not in proper hex format", s);
/* Invalid input. */
debug_return_int(-1);
}
}
debug_return_int((result[0] << 4) | result[1]);