Skip to content

Commit 6535d18

Browse files
authored
Merge branch 'master' into new/parallel
2 parents cb80ce0 + 7553cb7 commit 6535d18

23 files changed

Lines changed: 175 additions & 409 deletions

File tree

.github/workflows/codeql.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
contents: read
2222
security-events: write
2323
container:
24-
image: ghcr.io/void-linux/void-glibc-full:20240526R1
24+
image: ghcr.io/void-linux/void-glibc-full:20260210R1
2525
steps:
2626
- name: Prepare container
2727
run: |
@@ -30,21 +30,22 @@ jobs:
3030
# node-based actions require libstdc++.so.6
3131
# codeql runs some bash scripts
3232
xbps-install -Sy \
33-
libstdc++ bash git \
33+
libstdc++ bash git atf-devel kyua \
3434
gcc make pkg-config zlib-devel openssl-devel libarchive-devel
3535
- name: Checkout repository
3636
uses: actions/checkout@v3
3737
- run: git config --global --add safe.directory $(pwd)
3838
- name: Initialize CodeQL
39-
uses: github/codeql-action/init@v3
39+
uses: github/codeql-action/init@v4
4040
with:
41-
languages: cpp
41+
languages: c-cpp
42+
build-mode: manual
4243
config-file: ./.github/codeql/codeql-config.yaml
4344
- name: Build xbps
4445
run: |
45-
./configure
46+
./configure --enable-tests
4647
make -j
4748
- name: Perform CodeQL Analysis
48-
uses: github/codeql-action/analyze@v3
49+
uses: github/codeql-action/analyze@v4
4950
with:
5051
category: "/language:cpp"

bin/xbps-checkvers/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,8 @@ static int
537537
rcv_check_version(rcv_t *rcv)
538538
{
539539
const char *repover = NULL;
540-
char srcver[BUFSIZ] = { '\0' }, *binpkgname = NULL, *s = NULL;
541-
const char *pkgname, *version, *revision, *reverts, *repourl;
540+
char srcver[BUFSIZ] = { '\0' }, *binpkgname = NULL;
541+
const char *pkgname, *version, *revision, *reverts, *repourl, *s;
542542
int sz;
543543
size_t len;
544544

@@ -660,8 +660,8 @@ template_removed_cb(struct xbps_handle *xhp UNUSED,
660660
void *arg,
661661
bool *done UNUSED)
662662
{
663+
const char *last_dash;
663664
char *pkgname;
664-
char *last_dash;
665665
bool dummy_bool = false;
666666
rcv_t *rcv = arg;
667667

bin/xbps-create/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ process_one_alternative(const char *altgrname, const char *val)
235235
{
236236
xbps_dictionary_t d;
237237
xbps_array_t a;
238-
char *altfiles;
238+
const char *altfiles;
239239
bool alloc = false;
240240

241241
if ((d = xbps_dictionary_get(pkg_propsd, "alternatives")) == NULL) {
@@ -575,7 +575,7 @@ walk_dir(const char *path,
575575
{
576576
char tmp_path[PATH_MAX] = "";
577577
struct stat sb;
578-
struct dirent **list;
578+
struct dirent **list = NULL;
579579
int rv = 0;
580580
int n;
581581

bin/xbps-install/transaction.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <stdlib.h>
2929
#include <string.h>
3030
#include <errno.h>
31-
#include <ctype.h>
3231
#include <assert.h>
3332
#include <unistd.h>
3433
#include <limits.h>
@@ -317,9 +316,7 @@ dist_upgrade(struct xbps_handle *xhp, unsigned int cols, bool yes, bool drun)
317316
xbps_error_printf("No packages currently registered.\n");
318317
return 0;
319318
} else if (rv == EBUSY) {
320-
if (drun) {
321-
rv = 0;
322-
} else {
319+
if (!drun) {
323320
xbps_error_printf("The 'xbps' package must be updated, please run `xbps-install -u xbps`\n");
324321
return rv;
325322
}

bin/xbps-remove/clean-cache.c

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
102102
pkgd = xbps_pkgdb_get_pkg(xhp, binpkgver);
103103
} else {
104104
pkgd = xbps_rpool_get_pkg(xhp, binpkgver);
105+
if (!pkgd)
106+
pkgd = xbps_pkgdb_get_pkg(xhp, binpkgver);
105107
}
106108
if (pkgd) {
107109
xbps_dictionary_get_cstring_nocopy(pkgd,
@@ -143,20 +145,42 @@ clean_cachedir(struct xbps_handle *xhp, bool uninstalled, bool drun)
143145
DIR *dirp;
144146
struct dirent *dp;
145147
char *ext;
146-
int rv = 0;
148+
int r;
147149

148150
// XXX: there is no public api to load the pkgdb so force it before
149151
// its done potentially concurrently by threads through the
150152
// xbps_array_foreach_cb_multi call later.
151-
(void)xbps_pkgdb_get_pkg(xhp, "foo");
153+
// XXX: same for the repository pool...
154+
if (uninstalled) {
155+
(void)xbps_pkgdb_get_pkg(xhp, "package-that-wont-exist");
156+
} else {
157+
(void)xbps_rpool_get_pkg(xhp, "package-that-wont-exist-so-it-loads-all-repos");
158+
(void)xbps_pkgdb_get_pkg(xhp, "package-that-wont-exist");
159+
}
152160

153-
if (chdir(xhp->cachedir) == -1)
154-
return -1;
161+
if (chdir(xhp->cachedir) == -1) {
162+
if (errno == ENOENT)
163+
return 0;
164+
r = -errno;
165+
xbps_error_printf("failed to change to cache directory: %s: %s\n",
166+
xhp->cachedir, strerror(-r));
167+
return r;
168+
}
155169

156-
if ((dirp = opendir(xhp->cachedir)) == NULL)
157-
return 0;
170+
dirp = opendir(".");
171+
if (!dirp) {
172+
r = -errno;
173+
xbps_error_printf("failed to open cache directory: %s: %s\n",
174+
xhp->cachedir, strerror(-r));
175+
return r;
176+
}
158177

159178
array = xbps_array_create();
179+
if (!array) {
180+
(void)closedir(dirp);
181+
return xbps_error_oom();
182+
}
183+
160184
while ((dp = readdir(dirp)) != NULL) {
161185
if ((strcmp(dp->d_name, ".") == 0) ||
162186
(strcmp(dp->d_name, "..") == 0))
@@ -169,7 +193,11 @@ clean_cachedir(struct xbps_handle *xhp, bool uninstalled, bool drun)
169193
xbps_dbg_printf("ignoring unknown file: %s\n", dp->d_name);
170194
continue;
171195
}
172-
xbps_array_add_cstring(array, dp->d_name);
196+
if (!xbps_array_add_cstring(array, dp->d_name)) {
197+
xbps_object_release(array);
198+
(void)closedir(dirp);
199+
return xbps_error_oom();
200+
}
173201
}
174202
(void)closedir(dirp);
175203

@@ -178,8 +206,11 @@ clean_cachedir(struct xbps_handle *xhp, bool uninstalled, bool drun)
178206
.dry = drun,
179207
.uninstalled = uninstalled,
180208
};
181-
rv = xbps_array_foreach_cb_multi(xhp, array, NULL, cleaner_cb, (void*)&data);
182-
xbps_object_release(array);
209+
r = xbps_array_foreach_cb_multi(xhp, array, NULL, cleaner_cb, (void*)&data);
210+
} else {
211+
r = 0;
183212
}
184-
return rv;
213+
214+
xbps_object_release(array);
215+
return r;
185216
}

bin/xbps-uchroot/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ static void
212212
add_bindmount(const char *bm, bool ro)
213213
{
214214
struct bindmnt *bmnt;
215-
char *b, *src, *dest;
215+
const char *dest, *b;
216+
char *src;
216217
size_t len;
217218

218219
src = strdup(bm);

include/xbps.h.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,16 @@ int xbps_error_errno(int r, const char *fmt, ...) PRINTF_LIKE(2, 3);
781781
xbps_error_errno(ENOMEM, "%s:%d %s: out of memory\n", __FILE__, \
782782
__LINE__, __func__)
783783

784+
/**
785+
* @brief Log and abort for code that should be unreachable.
786+
*/
787+
#define xbps_unreachable() \
788+
do { \
789+
xbps_error_printf("%s:%d %s: code should not be reached\n", \
790+
__FILE__, __LINE__, __func__); \
791+
abort(); \
792+
} while (0)
793+
784794
/**@}*/
785795

786796
/** @addtogroup configure */

lib/archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ xbps_archive_get_file(struct archive *ar, struct archive_entry *entry)
5757

5858
buf = malloc(len + 1);
5959
if (!buf) {
60-
xbps_error_printf("out of memory\n");
60+
xbps_error_oom();
6161
errno = ENOMEM;
6262
return NULL;
6363
}

lib/conf.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ vpkg_map_add(xbps_dictionary_t d, const char *pkgname, const char *vpkgver, cons
6161
if (!providers) {
6262
providers = xbps_dictionary_create();
6363
if (!providers)
64-
return -ENOMEM;
64+
return xbps_error_oom();
6565

6666
if (!xbps_dictionary_set(d, pkgname, providers)) {
6767
xbps_object_release(providers);
68-
return -ENOMEM;
68+
return xbps_error_oom();
6969
}
7070
alloc = true;
7171
}
7272

7373
if (!xbps_dictionary_set_cstring(providers, vpkgver, provider)) {
7474
if (alloc)
7575
xbps_object_release(providers);
76-
return -ENOMEM;
76+
return xbps_error_oom();
7777
}
7878

7979
if (alloc)
@@ -249,9 +249,10 @@ cmpkey(const void *a, const void *b)
249249
static int
250250
parse_option(char *line, size_t linelen, char **valp, size_t *vallen)
251251
{
252-
size_t len;
252+
struct key needle;
253+
const struct key *result;
253254
char *p;
254-
struct key needle, *result;
255+
size_t len;
255256

256257
p = strpbrk(line, " \t=");
257258
if (p == NULL)

lib/fetch/fetch.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ fetchList(struct url_list *ue, struct url *URL, const char *pattern,
161161
return (fetchListFile(ue, URL, pattern, flags));
162162
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
163163
return (fetchListFTP(ue, URL, pattern, flags));
164-
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
165-
return (fetchListHTTP(ue, URL, pattern, flags));
166-
else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0)
167-
return (fetchListHTTP(ue, URL, pattern, flags));
168164
url_seterr(URL_BAD_SCHEME);
169165
return -1;
170166
}

0 commit comments

Comments
 (0)