diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-04-29 19:03:07 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-04-29 19:11:35 (EDT) |
commit | cb09917d64f9b2c20a699db0da97eee4560abd84 (patch) | |
tree | f3daff6afb6d96ca7c9013e6716b29ecf0226eb6 | |
parent | f217727c24c3cf1ec566a888ef409302377bb8d3 (diff) |
opk: Ensure data file names begin with "/"
-rw-r--r-- | src/opk.c | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -398,9 +398,9 @@ _opkg_opk_opk_read_data(struct opkg_opk_opk *opk) char *buffer; size_t size; long int size_len_max; - char fmt[28]; - /* "%c%s %-32s/%-32s %11d %s %s" */ - size_t len; + char fmt[26]; + /* "%c%s %-32s/%-32s %11d %s " */ + int len; char mode[10]; char mtime[20]; @@ -502,7 +502,7 @@ _opkg_opk_opk_read_data(struct opkg_opk_opk *opk) } ret = OPKG_OPK_OK; size_len_max = lrint(ceil(log10(size_max))); - snprintf(fmt, sizeof(fmt), "%%c%%s %%-%zus/%%-%zus %%%lid %%s %%s", + snprintf(fmt, sizeof(fmt), "%%c%%s %%-%zus/%%-%zus %%%lid %%s ", uname_len_max, gname_len_max, size_len_max); len = 34 + uname_len_max + gname_len_max + size_len_max; for (member = head; member != NULL;) { @@ -525,11 +525,24 @@ _opkg_opk_opk_read_data(struct opkg_opk_opk *opk) #pragma GCC diagnostic ignored "-Wformat-nonliteral" if (printf(fmt, member->type, mode, member->uname, member->gname, - member->size, mtime, member->name) != - (int) (len + strlen(member->name))) { + member->size, mtime) != len) { ret = OPKG_OPK_ERROR; } #pragma GCC diagnostic pop + /* Print name, ensuring it begins with "/". */ + if (member->name[0] == '.' && member->name[1] == '/') { + if (fputs(member->name + 1, stdout) == EOF) { + ret = OPKG_OPK_ERROR; + } + } else { + if (member->name[0] != '/' && putchar('/') == EOF) { + ret = OPKG_OPK_ERROR; + } + if (fputs(member->name, stdout) == EOF) { + ret = OPKG_OPK_ERROR; + } + } + /* Print link name, if any. */ if (member->type == 'l' && printf(" -> %s", member->linkname) != (int) (strlen(member->linkname) + 4)) { ret = OPKG_OPK_ERROR; |