Skip to content

Commit

Permalink
Merge commit '71a9418c8d1de1ca95b8ce898da21b820e508553'
Browse files Browse the repository at this point in the history
  • Loading branch information
laffer1 committed Sep 19, 2023
2 parents 4bd85f4 + 71a9418 commit 7bccc53
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 35 deletions.
10 changes: 5 additions & 5 deletions contrib/mport/libexec/mport.create/mport.create.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int main(int argc, char *argv[])
while ((ch = getopt(argc, argv, "C:D:E:M:O:P:S:c:d:e:f:i:j:l:m:n:o:p:r:s:t:v:x:")) != -1) {
switch (ch) {
case 'o':
extra->pkg_filename = strdup(optarg);
strlcpy(extra->pkg_filename, optarg, sizeof(extra->pkg_filename));
break;
case 'n':
if (optarg != NULL) {
Expand Down Expand Up @@ -104,7 +104,7 @@ int main(int argc, char *argv[])
}
break;
case 's':
extra->sourcedir = strdup(optarg);
strlcpy(extra->sourcedir, optarg, sizeof(extra->sourcedir));
break;
case 'd':
if (optarg != NULL) {
Expand Down Expand Up @@ -132,7 +132,7 @@ int main(int argc, char *argv[])
}
break;
case 'D':
mport_parselist(optarg, &(extra->depends));
mport_parselist(optarg, &(extra->depends), &(extra->depends_count));
break;
case 'M':
extra->mtree = strdup(optarg);
Expand All @@ -143,7 +143,7 @@ int main(int argc, char *argv[])
}
break;
case 'C':
mport_parselist(optarg, &(extra->conflicts));
mport_parselist(optarg, &(extra->conflicts), &(extra->conflicts_count));
break;
case 'E':
strptime(optarg, "%Y-%m-%d", &expDate);
Expand All @@ -165,7 +165,7 @@ int main(int argc, char *argv[])
extra->pkgmessage = strdup(optarg);
break;
case 't':
mport_parselist(optarg, &(pack->categories));
mport_parselist(optarg, &(pack->categories), &(pack->categories_count));
break;
case 'x':
if (optarg != NULL) {
Expand Down
5 changes: 3 additions & 2 deletions contrib/mport/libmport/bundle_read_update_pkg.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ static int build_create_extras(mportInstance *mport, mportPackageMeta *pkg, char
extra = mport_createextras_new();
*extra_p = extra;

extra->pkg_filename = strdup(tempfile); /* this MUST be on the heap, as it will be freed */
extra->sourcedir = strdup("");
strlcpy(extra->pkg_filename, tempfile, FILENAME_MAX);
extra->sourcedir[0] = '\0';

if (build_create_extras_depends(mport, pkg, extra) != MPORT_OK)
RETURN_CURRENT_ERROR;
Expand Down Expand Up @@ -205,6 +205,7 @@ static int build_create_extras_depends(mportInstance *mport, mportPackageMeta *p

if ((extra->depends = (char **)calloc(count + 1, sizeof(char *))) == NULL)
RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
extra->depends_count = count;

if (mport_db_prepare(mport->db, &stmt, "SELECT depend_pkgname, depend_pkgversion, depend_port FROM depends WHERE pkg=%Q", pkg->name) != MPORT_OK) {
sqlite3_finalize(stmt);
Expand Down
9 changes: 6 additions & 3 deletions contrib/mport/libmport/mport.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ typedef struct {
char *prefix;
char *origin;
char **categories;
size_t categories_count;
char *os_release;
char *cpe;
int locked;
Expand Down Expand Up @@ -253,11 +254,13 @@ typedef struct package_message {
} mportPackageMessage;

typedef struct {
char *pkg_filename;
char *sourcedir;
char pkg_filename[FILENAME_MAX];
char sourcedir[FILENAME_MAX];
char **depends;
size_t depends_count;
char *mtree;
char **conflicts;
size_t conflicts_count;
char *pkginstall;
char *pkgdeinstall;
char *pkgmessage;
Expand Down Expand Up @@ -322,7 +325,7 @@ int mport_setting_set(mportInstance *, const char *, const char *);
char ** mport_setting_list(mportInstance *);

/* Utils */
void mport_parselist(char *, char ***);
void mport_parselist(char *, char ***, size_t *);
int mport_verify_hash(const char *, const char *);
int mport_file_exists(const char *);
char * mport_version(mportInstance *);
Expand Down
53 changes: 28 additions & 25 deletions contrib/mport/libmport/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ mport_createextras_new(void)
if (extra == NULL)
return NULL;

extra->pkg_filename = NULL;
extra->sourcedir = NULL;
extra->pkg_filename[0] = '\0';
extra->sourcedir[0] = '\0';
extra->mtree = NULL;
extra->pkginstall = NULL;
extra->pkgdeinstall = NULL;
Expand All @@ -78,15 +78,11 @@ mport_createextras_new(void)
MPORT_PUBLIC_API void
mport_createextras_free(mportCreateExtras *extra)
{
int i;
size_t i;

if (extra == NULL)
return;

free(extra->pkg_filename);
extra->pkg_filename = NULL;
free(extra->sourcedir);
extra->sourcedir = NULL;
free(extra->mtree);
extra->mtree = NULL;
free(extra->pkginstall);
Expand All @@ -96,24 +92,26 @@ mport_createextras_free(mportCreateExtras *extra)
free(extra->pkgmessage);
extra->pkgmessage = NULL;

i = 0;
if (extra->conflicts != NULL) {
while (extra->conflicts[i] != NULL) {
if (extra->conflicts_count > 0 && extra->conflicts != NULL) {
for (i = 0; i < extra->conflicts_count; i++) {
if (extra->conflicts[i] == NULL) {
break;
}
free(extra->conflicts[i]);
extra->conflicts[i] = NULL;
i++;
}

free(extra->conflicts);
extra->conflicts = NULL;
}

i = 0;
if (extra->depends != NULL) {
while (extra->depends[i] != NULL) {
if (extra->depends_count > 0 && extra->depends != NULL) {
for (i = 0; i < extra->depends_count; i++) {
if (extra->depends[i] == NULL) {
break;
}
free(extra->depends[i]);
extra->depends[i] = NULL;
i++;
}

free(extra->depends);
Expand Down Expand Up @@ -414,14 +412,14 @@ mport_xsystem(mportInstance *mport, const char *fmt, ...)
*
* char input[] = "foo bar baz"
* char **list;
* size_t list_size;
*
* mport_parselist(input, &list);
* mport_parselist(input, &list, &list_size);
* list = {"foo", "bar", "baz"};
*/
void
mport_parselist(char *opt, char ***list)
mport_parselist(char *opt, char ***list, size_t *list_size)
{
size_t len;
char *input;
char *field;

Expand All @@ -432,28 +430,33 @@ mport_parselist(char *opt, char ***list)
}

/* first we need to get the length of the dependency list */
for (len = 0; (field = strsep(&opt, " \t\n")) != NULL;) {
for (*list_size = 0; (field = strsep(&opt, " \t\n")) != NULL;) {
if (*field != '\0')
len++;
(*list_size)++;
}

if ((*list = (char **)calloc((len + 1), sizeof(char *))) == NULL) {
if (*list_size == 0) {
**list = NULL;
return;
}

if (len == 0) {
**list = NULL;
if ((*list = (char **)calloc((*list_size + 1), sizeof(char *))) == NULL) {
return;
}

/* dereference once so we don't lose our minds. */
char **vec = *list;

size_t loc = 0;
while ((field = strsep(&input, " \t\n")) != NULL) {
if (loc == *list_size)
break;

if (*field == '\0')
continue;

*vec = field;
*vec = strdup(field);
loc++;
vec++;
}

Expand Down
1 change: 1 addition & 0 deletions contrib/mport/mport/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PROG= mport

CFLAGS= -I ../libmport/ -g -L../libmport -lmport -lutil
CFLAGS+= -Werror -Wunused-variable -Wshadow -Wincompatible-pointer-types-discards-qualifiers

LIBADD+= mport util

Expand Down

0 comments on commit 7bccc53

Please sign in to comment.