diff --git a/impacket/tds.py b/impacket/tds.py index 1f0d546342..4641f3fb98 100644 --- a/impacket/tds.py +++ b/impacket/tds.py @@ -574,7 +574,7 @@ def parse(self): Parsed value in its appropriate Python type, or 'NULL' if empty """ if self["TotalLength"] == 0: - return "NULL" + return None data = self["Data"] @@ -707,7 +707,7 @@ def _parseValue(self, baseType, data, properties): # date: 3-byte unsigned integer (days since year 1) # VARIANT_PROPBYTES = 0 if len(data) < 3: - return "NULL" + return None dateValue = struct.unpack(" 1 else 0 if len(data) == 0: - return "NULL" + return None # First byte is sign (1 = positive, 0 = negative) sign = 1 if data[0] == 1 else -1 @@ -1660,8 +1660,9 @@ def processColMeta(self): col["minLenght"] = 0 for row in self.rows: - if len(str(row[col["Name"]])) > col["minLenght"]: - col["minLenght"] = len(str(row[col["Name"]])) + display = "NULL" if row[col["Name"]] is None else str(row[col["Name"]]) + if len(display) > col["minLenght"]: + col["minLenght"] = len(display) if col["minLenght"] < col["Length"]: col["Length"] = col["minLenght"] @@ -1691,8 +1692,10 @@ def printRows(self): self.printColumnsHeader() for row in self.rows: for col in self.colMeta: + value = row[col["Name"]] + display = "NULL" if value is None else value self.__rowsPrinter.logMessage( - col["Format"] % row[col["Name"]] + self.COL_SEPARATOR + col["Format"] % display + self.COL_SEPARATOR ) self.__rowsPrinter.logMessage("\r") @@ -1776,7 +1779,7 @@ def parseRow(self, token, tuplemode=False): value = data[:charLen].decode("utf-16le") data = data[charLen:] else: - value = "NULL" + value = None elif _type == TDS_BIGVARCHRTYPE: charLen = struct.unpack("