Re: rpki-client, unify err() for out of memory situation

2021-03-02 Thread Theo de Raadt
Theo Buehler  wrote:

> On Tue, Mar 02, 2021 at 02:09:37PM +0100, Claudio Jeker wrote:
> > This diff just brings all err(3) calls for out of memory situations to one
> > form: err(1, NULL);
> > It is not very helpful to tell if malloc, strdup or asprintf failed with no
> > mem. Just one common idiom.
> > 
> > OK?
> 
> ok.
> 
> The https diff will again add a few more of those.

This is similar to the following pattern found throughout the tree:

pflogd/privsep.c:   err(1, "unveil");

I really dislike such, as obviously it should show the path.  Being
able to discern specific failures more accurately is obviously helpful.



Re: rpki-client, unify err() for out of memory situation

2021-03-02 Thread Theo Buehler
On Tue, Mar 02, 2021 at 02:09:37PM +0100, Claudio Jeker wrote:
> This diff just brings all err(3) calls for out of memory situations to one
> form: err(1, NULL);
> It is not very helpful to tell if malloc, strdup or asprintf failed with no
> mem. Just one common idiom.
> 
> OK?

ok.

The https diff will again add a few more of those.



rpki-client, unify err() for out of memory situation

2021-03-02 Thread Claudio Jeker
This diff just brings all err(3) calls for out of memory situations to one
form: err(1, NULL);
It is not very helpful to tell if malloc, strdup or asprintf failed with no
mem. Just one common idiom.

OK?
-- 
:wq Claudio

Index: main.c
===
RCS file: /cvs/src/usr.sbin/rpki-client/main.c,v
retrieving revision 1.108
diff -u -p -r1.108 main.c
--- main.c  2 Mar 2021 09:23:59 -   1.108
+++ main.c  2 Mar 2021 13:03:30 -
@@ -227,7 +227,7 @@ entityq_add(struct entityq *q, char *fil
struct entity   *p;
 
if ((p = calloc(1, sizeof(struct entity))) == NULL)
-   err(1, "calloc");
+   err(1, NULL);
 
p->type = type;
p->file = file;
@@ -236,12 +236,12 @@ entityq_add(struct entityq *q, char *fil
if (p->has_pkey) {
p->pkeysz = pkeysz;
if ((p->pkey = malloc(pkeysz)) == NULL)
-   err(1, "malloc");
+   err(1, NULL);
memcpy(p->pkey, pkey, pkeysz);
}
if (descr != NULL)
if ((p->descr = strdup(descr)) == NULL)
-   err(1, "strdup");
+   err(1, NULL);
 
filepath_add(file);
 
@@ -270,7 +270,7 @@ repo_alloc(void)
rt.repos = recallocarray(rt.repos, rt.reposz, rt.reposz + 1,
sizeof(struct repo));
if (rt.repos == NULL)
-   err(1, "recallocarray");
+   err(1, NULL);
 
rp = &rt.repos[rt.reposz++];
rp->id = rt.reposz - 1;
@@ -320,7 +320,7 @@ ta_lookup(const struct tal *tal)
size_t  i, j;
 
if (asprintf(&local, "ta/%s", tal->descr) == -1)
-   err(1, "asprinf");
+   err(1, NULL);
 
/* Look up in repository table. (Lookup should actually fail here) */
for (i = 0; i < rt.reposz; i++) {
@@ -336,7 +336,7 @@ ta_lookup(const struct tal *tal)
if (strncasecmp(tal->uri[i], "rsync://", 8) != 0)
continue;   /* ignore non rsync URI for now */
if ((rp->uris[j++] = strdup(tal->uri[i])) == NULL)
-   err(1, "strdup");
+   err(1, NULL);
}
if (j == 0)
errx(1, "TAL file has no rsync:// URI");
@@ -370,10 +370,10 @@ repo_lookup(const char *uri)
rp = repo_alloc();
rp->repouri = repo;
local = strchr(repo, ':') + strlen("://");
-   if (asprintf(&rp->local, "rsync/%s", local) == -1)
-   err(1, "asprintf");
+   if ((rp->local = strdup(repo)) == NULL)
+   err(1, NULL);
if ((rp->uris[0] = strdup(repo)) == NULL)
-   err(1, "strdup");
+   err(1, NULL);
 
repo_fetch(rp);
return rp;
@@ -392,7 +392,7 @@ repo_filename(const struct repo *repo, c
uri += strlen(repo->repouri) + 1;   /* skip base and '/' */
 
if (asprintf(&nfile, "%s/%s", repo->local, uri) == -1)
-   err(1, "asprintf");
+   err(1, NULL);
return nfile;
 }
 
@@ -411,7 +411,7 @@ queue_add_from_mft(struct entityq *q, co
assert(cp != NULL);
assert(cp - mft < INT_MAX);
if (asprintf(&nfile, "%.*s/%s", (int)(cp - mft), mft, file->file) == -1)
-   err(1, "asprintf");
+   err(1, NULL);
 
/*
 * Since we're from the same directory as the MFT file, we know
@@ -493,7 +493,7 @@ queue_add_tal(struct entityq *q, const c
char*nfile, *buf;
 
if ((nfile = strdup(file)) == NULL)
-   err(1, "strdup");
+   err(1, NULL);
buf = tal_read_file(file);
 
/* Record tal for later reporting */
@@ -502,7 +502,7 @@ queue_add_tal(struct entityq *q, const c
else {
char *tmp;
if (asprintf(&tmp, "%s %s", stats.talnames, file) == -1)
-   err(1, "asprintf");
+   err(1, NULL);
free(stats.talnames);
stats.talnames = tmp;
}
@@ -531,7 +531,7 @@ queue_add_from_tal(struct entityq *q, co
uri = strrchr(repo->uris[0], '/');
assert(uri);
if (asprintf(&nfile, "%s/%s", repo->local, uri + 1) == -1)
-   err(1, "asprintf");
+   err(1, NULL);
 
entityq_add(q, nfile, RTYPE_CER, repo, tal->pkey,
tal->pkeysz, tal->descr);
@@ -672,7 +672,7 @@ tal_load_default(const char *tals[], siz
err(1, "too many tal files found in %s",
confdir);
if (asprintf(&path, "%s/%s", confdir, dp->d_name) == -1)
-   err(1, "asprintf");
+   err(1, NULL);
tals[s++] = path;
}
closedir (dirp);
@@ -686,10 +686,9 @@ add_to_del(char **del, size_t *dsz, char
 
del = reallocarray(del, i + 1, sizeof(*del));
if (del == NULL)