Skip to content

Commit fa2c3c5

Browse files
committed
Don't forget to squash this commit
1 parent 58526c2 commit fa2c3c5

1 file changed

Lines changed: 21 additions & 31 deletions

File tree

libclamav/iso9660.c

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -100,37 +100,22 @@ static cl_error_t iso_scan_file(const iso9660_t *iso, unsigned int block, unsign
100100

101101
static char *iso_string(iso9660_t *iso, const void *src, unsigned int len)
102102
{
103-
104-
memset(iso->buf, 0, sizeof(iso->buf));
105-
106103
if (iso->joliet) {
107-
char *utf8 = NULL;
108-
const char *uutf8 = NULL;
109-
110-
if (cli_isutf8(src, len)) {
111-
uutf8 = src;
112-
} else {
113-
114-
if (len > (sizeof(iso->buf) - 2)) {
115-
len = sizeof(iso->buf) - 2;
116-
}
117-
utf8 = cli_utf16_to_utf8(src, len, E_UTF16_BE);
118-
if (utf8 && cli_isutf8(utf8, len)) {
119-
uutf8 = utf8;
120-
} else {
121-
uutf8 = "";
122-
}
123-
}
124-
104+
char *utf8;
105+
const char *uutf8;
106+
if (len > (sizeof(iso->buf) - 2))
107+
len = sizeof(iso->buf) - 2;
108+
memcpy(iso->buf, src, len);
109+
iso->buf[len] = '\0';
110+
iso->buf[len + 1] = '\0';
111+
utf8 = cli_utf16_to_utf8(iso->buf, len, E_UTF16_BE);
112+
uutf8 = utf8 ? utf8 : "";
125113
strncpy(iso->buf, uutf8, sizeof(iso->buf));
126-
iso->buf[sizeof(iso->buf) - 1] = 0;
127-
FREE(utf8);
114+
iso->buf[sizeof(iso->buf) - 1] = '\0';
115+
free(utf8);
128116
} else {
129-
if (len > (sizeof(iso->buf) - 1)) {
130-
len = sizeof(iso->buf) - 1;
131-
}
132117
memcpy(iso->buf, src, len);
133-
iso->buf[len] = 0;
118+
iso->buf[len] = '\0';
134119
}
135120
return iso->buf;
136121
}
@@ -243,8 +228,9 @@ cl_error_t cli_scaniso(cli_ctx *ctx, size_t offset)
243228
const uint8_t *privol, *next;
244229
iso9660_t iso;
245230
int i;
246-
cl_error_t status = CL_SUCCESS;
247-
cl_error_t ret = CL_SUCCESS;
231+
cl_error_t status = CL_SUCCESS;
232+
cl_error_t ret = CL_SUCCESS;
233+
uint32_t nextJoliet = 0;
248234

249235
if (offset < 32768) {
250236
/* Need 16 sectors at least 2048 bytes long */
@@ -312,6 +298,9 @@ cl_error_t cli_scaniso(cli_ctx *ctx, size_t offset)
312298
next = NULL;
313299
}
314300

301+
nextJoliet = iso.joliet;
302+
iso.joliet = 0;
303+
315304
do {
316305
cli_dbgmsg("in cli_scaniso\n");
317306
if (cli_debug_flag) {
@@ -382,8 +371,9 @@ cl_error_t cli_scaniso(cli_ctx *ctx, size_t offset)
382371
status = ret;
383372
}
384373

385-
privol = next;
386-
next = NULL;
374+
privol = next;
375+
next = NULL;
376+
iso.joliet = nextJoliet;
387377

388378
} while (privol);
389379

0 commit comments

Comments
 (0)