From 4caeb0dbe0417cf53e5f53d2dbbd5e521bfe845c Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Thu, 7 Dec 2006 22:18:53 +0000
Subject: [PATCH] Fix for incorrectly generated masks for task/affinity plugin 
    patch.1.2.0-pre9.061207.bitfmthex from Dan Palermo (HP).

---
 NEWS                   |  2 ++
 src/common/bitstring.c | 25 ++++++++++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index e20f5718b81..914f53d0904 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,8 @@ documents those changes that are of interest to users and admins.
     reconfig.
  -- Added new slurm.conf parameter TaskPluginParam.
  -- Fix for job requeue and credential revoke logic from Hongjia Cao (NUDT).
+ -- Fix for incorrectly generated masks for task/affinity plugin
+    patch.1.2.0-pre9.061207.bitfmthex from Dan Palermo (HP).
 
 * Changes in SLURM 1.2.0-pre9
 =============================
diff --git a/src/common/bitstring.c b/src/common/bitstring.c
index 361fea112ed..922137d435c 100644
--- a/src/common/bitstring.c
+++ b/src/common/bitstring.c
@@ -42,6 +42,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "src/common/bitstring.h"
 #include "src/common/macros.h"
@@ -1034,8 +1035,11 @@ char * bit_fmt_hexmask(bitstr_t * bitmap)
 		if ((i < bitsize) && bit_test(bitmap,i++)) current |= 0x2;
 		if ((i < bitsize) && bit_test(bitmap,i++)) current |= 0x4;
 		if ((i < bitsize) && bit_test(bitmap,i++)) current |= 0x8;
-		current += '0';
-		if (current > '9') current += ('A' - '9');
+		if (current <= 9) {
+			current += '0';
+		} else {
+			current += 'A' - 10;
+		}
 		*ptr-- = current;
 	}
 
@@ -1054,6 +1058,7 @@ char * bit_fmt_hexmask(bitstr_t * bitmap)
 int bit_unfmt_hexmask(bitstr_t * bitmap, const char* str) 
 {
 	int bit_index = 0, len = strlen(str);
+	int rc = 0;
 	const char *curpos = str + len - 1;
 	char current;
 	bitoff_t bitsize = bit_size(bitmap);
@@ -1065,8 +1070,18 @@ int bit_unfmt_hexmask(bitstr_t * bitmap, const char* str)
 
 	while(curpos >= str) {
 		current = (int) *curpos; 
-		if (current <= '9') current -= '0';
-		if (current > '9') current -= ('A' - '9');
+		if (isxdigit(current)) {	/* valid hex digit */
+			if (isdigit(current)) {
+				current -= '0';
+			} else {
+				current = toupper(current);
+				current -= 'A' - 10;
+			}
+		} else {			/* not a valid hex digit */
+		    	current = 0;
+			rc = -1;
+		}
+
 		if ((current & 1) && (bit_index   < bitsize))
 			bit_set(bitmap, bit_index);
 		if ((current & 2) && (bit_index+1 < bitsize))
@@ -1079,7 +1094,7 @@ int bit_unfmt_hexmask(bitstr_t * bitmap, const char* str)
 		curpos--;
 		bit_index+=4;
 	}
-	return 0;
+	return rc;
 }
 
 /* bit_fmt_binmask
-- 
GitLab