Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmark committed Feb 15, 2025
1 parent 4cdc09f commit 501510b
Showing 1 changed file with 5 additions and 39 deletions.
44 changes: 5 additions & 39 deletions libatalk/vfs/ea_ad.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ static int unpack_header(struct ea * restrict ea)
uint16_t uint16;
uint32_t uint32;
char *buf;
size_t remaining;

/* Check magic and version */
buf = ea->ea_data;
Expand Down Expand Up @@ -155,15 +154,6 @@ static int unpack_header(struct ea * restrict ea)
if (ea->ea_count == 0)
return 0;

/* Check magic and version */
buf = ea->ea_data;
remaining = ea->ea_size;

if (remaining < EA_HEADER_SIZE) {
ret = -1;
goto exit;
}

/* Allocate storage for the ea_entries array */
ea->ea_entries = malloc(sizeof(struct ea_entry) * ea->ea_count);
if ( ! ea->ea_entries) {
Expand All @@ -172,35 +162,19 @@ static int unpack_header(struct ea * restrict ea)
goto exit;
}

buf = ea->ea_data + EA_HEADER_SIZE;
while (count < ea->ea_count) {
/* Check if we have enough bytes for EA size (4) + at least 1 char for name */
if (remaining < 5) {
ret = -1;
goto cleanup;
}

memcpy(&uint32, buf, 4); /* EA size */
buf += 4;
remaining -= 4;

/* Validate string length fits in remaining buffer */
size_t namelen = strnlen(buf, remaining);
if (namelen == remaining) { /* No null terminator found */
ret = -1;
goto cleanup;
}

/* Rest of the existing code */
(*(ea->ea_entries))[count].ea_size = ntohl(uint32);
(*(ea->ea_entries))[count].ea_name = strdup(buf);
if (! (*(ea->ea_entries))[count].ea_name) {
LOG(log_error, logtype_afpd, "unpack_header: OOM");
ret = -1;
goto cleanup;
goto exit;
}

(*(ea->ea_entries))[count].ea_namelen = namelen;
buf += namelen + 1;
remaining -= namelen + 1;
(*(ea->ea_entries))[count].ea_namelen = strlen((*(ea->ea_entries))[count].ea_name);
buf += (*(ea->ea_entries))[count].ea_namelen + 1;

LOG(log_maxdebug, logtype_afpd, "unpack_header: entry no:%u,\"%s\", size: %u, namelen: %u", count,
(*(ea->ea_entries))[count].ea_name,
Expand All @@ -210,14 +184,6 @@ static int unpack_header(struct ea * restrict ea)
count++;
}

cleanup:
while (count > 0) {
count--;
free((*(ea->ea_entries))[count].ea_name);
}
free(ea->ea_entries);
ea->ea_entries = NULL;

exit:
return ret;
}
Expand Down

0 comments on commit 501510b

Please sign in to comment.