summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-07-30 16:31:24 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-07-30 16:31:24 (EDT)
commit39260a1b5a737324043ba949a1791bd7aaaf8aac (patch)
tree100350d200f79c689e36b5d660e1e0b5d7029191
parentc1b7e91add52a38cd254969f2b2efd8cd6d001e6 (diff)
dirent: Distinguish overflow from argument error
-rw-r--r--opkg-opk/dirent.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/opkg-opk/dirent.c b/opkg-opk/dirent.c
index 575e834..0080d44 100644
--- a/opkg-opk/dirent.c
+++ b/opkg-opk/dirent.c
@@ -32,6 +32,7 @@ _opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, int is_dir,
size_t len;
char **buf;
int sep;
+ int ret;
len = strlen(dirent->name);
if ((*name_len > 0 || is_dir) && *name_len + len + 1 <= *name_buf_len) {
@@ -60,7 +61,7 @@ _opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, int is_dir,
sep = 0;
} else {
/* Both buffers full. */
- return OPKG_OPK_ERROR;
+ return OPKG_OPK_END;
}
if (*buf == NULL) {
/* Caller provided a NULL buffer pointer. */
@@ -68,11 +69,12 @@ _opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, int is_dir,
}
/* Recurse. */
- if (dirent->parent != NULL &&
- _opkg_opk_dirent_name_prefix(dirent->parent, is_dir,
- name_buf, name_buf_len, pref_buf, pref_buf_len,
- name_len, pref_len) == OPKG_OPK_ERROR) {
- return OPKG_OPK_ERROR;
+ if (dirent->parent != NULL && (ret =
+ _opkg_opk_dirent_name_prefix(dirent->parent,
+ is_dir, name_buf, name_buf_len,
+ pref_buf, pref_buf_len, name_len,
+ pref_len)) != OPKG_OPK_OK) {
+ return ret;
}
/* Copy node name and possibly separator suffix. */
@@ -95,16 +97,17 @@ opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, int is_dir,
size_t pref_len = 0;
char *name = name_buf;
char *pref = pref_buf;
+ int ret;
/* NUL bytes */
--name_buf_len;
--pref_buf_len;
- if (_opkg_opk_dirent_name_prefix(dirent, is_dir,
- &name_buf, &name_buf_len,
- &pref_buf, &pref_buf_len,
- &name_len, &pref_len) == OPKG_OPK_ERROR) {
- return OPKG_OPK_ERROR;
+ if ((ret = _opkg_opk_dirent_name_prefix(dirent, is_dir,
+ &name_buf, &name_buf_len,
+ &pref_buf, &pref_buf_len,
+ &name_len, &pref_len)) != OPKG_OPK_OK) {
+ return ret;
}
name[name_len] = '\0';