aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CheckpointRecovery.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/CheckpointRecovery.c b/src/CheckpointRecovery.c
index 9d6ab65..ba32fb7 100644
--- a/src/CheckpointRecovery.c
+++ b/src/CheckpointRecovery.c
@@ -65,6 +65,7 @@ typedef int (*recover_fn_t) (cGH *GH, const char *basefilename,int called_from);
********************************************************************/
static char *EncodeString (const char *string);
static char *DecodeString (const char *string);
+static int OctalDigitToInt (const char digit);
static void SetInputFlag (int vindex, const char *optstring, void *arg);
#ifdef HAVE_DIRENT_H
static int CompareFiles (const void *a, const void *b);
@@ -974,7 +975,7 @@ static char *EncodeString (const char *string)
{
if (! isprint (string[i]))
{
- sprintf (p, "\\%.03d", (unsigned char)string[i]);
+ sprintf (p, "\\%.03o", (unsigned char)string[i]);
p += 4;
}
else
@@ -997,6 +998,7 @@ static char *DecodeString (const char *string)
{
size_t i, len = strlen (string);
char *p, *retval;
+ int o1, o2, o3;
p = retval = malloc (len + 1);
@@ -1021,12 +1023,11 @@ static char *DecodeString (const char *string)
else
{
if (i+3 >= len) goto bail_out;
- if (! isdigit (string[i+1]) ||
- ! isdigit (string[i+2]) ||
- ! isdigit (string[i+3])) goto bail_out;
- *p++ = (char) (100*(string[i+1] - '0') +
- 10*(string[i+2] - '0') +
- 1*(string[i+3] - '0'));
+ o1 = OctalDigitToInt (string[i+1]);
+ o2 = OctalDigitToInt (string[i+2]);
+ o3 = OctalDigitToInt (string[i+3]);
+ if (o1 < 0 || o2 < 0 || o3 < 0) goto bail_out;
+ *p++ = (char) (8*8*o1 + 8*o2 + o3);
i += 3;
}
}
@@ -1109,6 +1110,27 @@ static void SetInputFlag (int vindex, const char *optstring, void *flags)
}
+/* Convert an octal digit to an integer. Return -1 if this is not an
+ octal digit. Note that this routine does not assume ASCII encoding
+ (and thus cannot calculate digit-'0'), and does not use
+ non-standard library function such as isoctal. */
+static int OctalDigitToInt (const char digit)
+{
+ switch (digit)
+ {
+ case '0': return 0;
+ case '1': return 1;
+ case '2': return 2;
+ case '3': return 3;
+ case '4': return 4;
+ case '5': return 5;
+ case '6': return 6;
+ case '7': return 7;
+ }
+ return -1;
+}
+
+
#ifdef HAVE_DIRENT_H
/* callback for qsort() to sort the list of recovery files found */
static int CompareFiles (const void *a, const void *b)