Skip to content

Commit 469b122

Browse files
committed
refactor: improve cbExtension comment and test coverage
- Clarify cbExtension comment to explicitly state it's the size of the ibFeatureExtLong pointer (4 bytes), not the FeatureExt data - Extend test to validate all variable-length fields when checking FeatureExt positioning, ensuring complete coverage per MS-TDS spec
1 parent 87692db commit 469b122

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/login7-payload.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,14 @@ class Login7Payload {
256256
offset = fixedData.writeUInt16LE(dataOffset, offset);
257257

258258
// (cchUnused / cbExtension): 2-byte
259-
// For TDS 7.4+, this is the size of the extension block (just the 4-byte offset pointer).
259+
// For TDS 7.4+, this is the size of the ibFeatureExtLong offset pointer (4 bytes).
260+
// The actual FeatureExt data is appended at the end of the packet, not here.
260261
// We'll store the FeatureExt data to append at the end after all other variable data.
261262
let featureExtData: Buffer | undefined;
262263
let extensionOffsetBuffer: Buffer | undefined;
263264
if (this.tdsVersion >= versions['7_4']) {
264265
featureExtData = this.buildFeatureExt();
265-
// cbExtension = 4 (just the ibFeatureExtLong pointer size)
266+
// cbExtension = 4 (size of the ibFeatureExtLong pointer, not the FeatureExt data)
266267
offset = fixedData.writeUInt16LE(4, offset);
267268
// Reserve space for the 4-byte offset pointer; we'll fill in the actual offset later
268269
extensionOffsetBuffer = Buffer.alloc(4);

test/unit/login7-payload-test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,39 @@ describe('Login7Payload', function() {
346346
// 86-89: ibChangePassword/cchChangePassword, 90-93: cbSSPILong
347347
const ibHostName = data.readUInt16LE(36);
348348
const cchHostName = data.readUInt16LE(38);
349+
const ibUserName = data.readUInt16LE(40);
350+
const cchUserName = data.readUInt16LE(42);
351+
const ibPassword = data.readUInt16LE(44);
352+
const cchPassword = data.readUInt16LE(46);
353+
const ibAppName = data.readUInt16LE(48);
354+
const cchAppName = data.readUInt16LE(50);
355+
const ibServerName = data.readUInt16LE(52);
356+
const cchServerName = data.readUInt16LE(54);
357+
const ibCltIntName = data.readUInt16LE(60);
358+
const cchCltIntName = data.readUInt16LE(62);
359+
const ibLanguage = data.readUInt16LE(64);
360+
const cchLanguage = data.readUInt16LE(66);
349361
const ibDatabase = data.readUInt16LE(68);
350362
const cchDatabase = data.readUInt16LE(70);
363+
const ibSSPI = data.readUInt16LE(78);
364+
const cbSSPI = data.readUInt16LE(80);
351365
const ibAttachDBFile = data.readUInt16LE(82);
352366
const cchAttachDBFile = data.readUInt16LE(84);
353367
const ibChangePassword = data.readUInt16LE(86);
354368
const cchChangePassword = data.readUInt16LE(88);
355369

356370
// Calculate the end of all regular variable data (excluding FeatureExt)
371+
// Include all variable-length fields to ensure complete coverage
357372
const variableDataEnd = Math.max(
358373
ibHostName + cchHostName * 2,
374+
ibUserName + cchUserName * 2,
375+
ibPassword + cchPassword * 2,
376+
ibAppName + cchAppName * 2,
377+
ibServerName + cchServerName * 2,
378+
ibCltIntName + cchCltIntName * 2,
379+
ibLanguage + cchLanguage * 2,
359380
ibDatabase + cchDatabase * 2,
381+
ibSSPI + cbSSPI,
360382
ibAttachDBFile + cchAttachDBFile * 2,
361383
ibChangePassword + cchChangePassword * 2
362384
);

0 commit comments

Comments
 (0)