Skip to content

Commit ccd231e

Browse files
committed
NSIS: When extracting files, get the path's basename when recording the name
In the scan metadata JSON, the result will be like this: ```json { "FileName":"headers", "FilePath":"/home/micah/tmp/20250702_173504-clam-nsis.exe.991ca413f9/clamav-b8d49de1082953f591c02163a128b90b.tmp/nulsft-tmp.1416a98706/headers", "FileSize":4357, "ObjectID":2 }, ``` ... instead of this: ```json { "FileName":"/home/micah/tmp/20250702_172320-clam-nsis.exe.1bfb389b2c/clamav-41fa5f1bc556577438b143bc2915f57c.tmp/nulsft-tmp.a851a869ee/headers", "FilePath":"/home/micah/tmp/20250702_172320-clam-nsis.exe.1bfb389b2c/clamav-41fa5f1bc556577438b143bc2915f57c.tmp/nulsft-tmp.a851a869ee/headers", "FileSize":4357, "ObjectID":2 }, ```json
1 parent dccb188 commit ccd231e

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

libclamav/nsis/nulsft.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,18 +539,31 @@ int cli_scannulsft(cli_ctx *ctx, off_t offset)
539539
continue;
540540
}
541541
if (ret == CL_SUCCESS) {
542+
char *name = NULL;
542543
cli_dbgmsg("NSIS: Successfully extracted file #%u\n", nsist.fno);
543544
if (lseek(nsist.ofd, 0, SEEK_SET) == -1) {
544545
cli_dbgmsg("NSIS: call to lseek() failed\n");
545546
free(nsist.dir);
546547
return CL_ESEEK;
547548
}
549+
550+
// Get basename of the file from nsist.ofn
551+
ret = cli_basename(nsist.ofn, strlen(nsist.ofn), &name);
552+
if (CL_SUCCESS != ret || NULL == name) {
553+
cli_dbgmsg("NSIS: Failed to get basename of the file\n");
554+
// If it fails, the name will just be NULL. That's okay.
555+
}
556+
548557
if (nsist.fno == 1) {
549-
ret = cli_scan_desc(nsist.ofd, ctx, CL_TYPE_ANY, false, NULL, AC_SCAN_VIR, NULL, nsist.ofn, nsist.ofn, LAYER_ATTRIBUTES_NONE); /// TODO: Extract file names
558+
ret = cli_scan_desc(nsist.ofd, ctx, CL_TYPE_ANY, false, NULL, AC_SCAN_VIR, NULL, name, nsist.ofn, LAYER_ATTRIBUTES_NONE); /// TODO: Extract file names
550559
} else {
551-
ret = cli_magic_scan_desc(nsist.ofd, nsist.ofn, ctx, nsist.ofn, LAYER_ATTRIBUTES_NONE); /// TODO: Extract file names
560+
ret = cli_magic_scan_desc(nsist.ofd, nsist.ofn, ctx, name, LAYER_ATTRIBUTES_NONE); /// TODO: Extract file names
552561
}
562+
563+
CLI_FREE_AND_SET_NULL(name);
564+
553565
close(nsist.ofd);
566+
554567
if (!ctx->engine->keeptmp) {
555568
if (cli_unlink(nsist.ofn)) {
556569
ret = CL_EUNLINK;

0 commit comments

Comments
 (0)