fix NULL deref in got_error_from_errno via got_error_uuid (found by jasper)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/include/got_error.h b/include/got_error.h
index b156fbf..97f0473 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -323,7 +323,7 @@ const struct got_error *got_error_no_obj(struct got_object_id *);
const struct got_error *got_error_not_ref(const char *);
/* Return an error based on a uuid(3) status code. */
-const struct got_error *got_error_uuid(uint32_t);
+const struct got_error *got_error_uuid(uint32_t, const char *);
/* Return an error with a path prefixed to the error message. */
const struct got_error *got_error_path(const char *, int);
diff --git a/lib/error.c b/lib/error.c
index 1c3c04a..92ce7a5 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -157,7 +157,7 @@ got_error_not_ref(const char *refname)
}
const struct got_error *
-got_error_uuid(uint32_t uuid_status)
+got_error_uuid(uint32_t uuid_status, const char *prefix)
{
switch (uuid_status) {
case uuid_s_ok:
@@ -167,7 +167,7 @@ got_error_uuid(uint32_t uuid_status)
case uuid_s_invalid_string_uuid:
return got_error(GOT_ERR_UUID_INVALID);
case uuid_s_no_memory:
- return got_error_set_errno(ENOMEM, NULL);
+ return got_error_set_errno(ENOMEM, prefix);
default:
return got_error(GOT_ERR_UUID);
}
diff --git a/lib/worktree.c b/lib/worktree.c
index 3991862..71909fd 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -284,12 +284,12 @@ got_worktree_init(const char *path, struct got_reference *head_ref,
/* Generate UUID. */
uuid_create(&uuid, &uuid_status);
if (uuid_status != uuid_s_ok) {
- err = got_error_uuid(uuid_status);
+ err = got_error_uuid(uuid_status, "uuid_create");
goto done;
}
uuid_to_string(&uuid, &uuidstr, &uuid_status);
if (uuid_status != uuid_s_ok) {
- err = got_error_uuid(uuid_status);
+ err = got_error_uuid(uuid_status, "uuid_to_string");
goto done;
}
err = create_meta_file(path_got, GOT_WORKTREE_UUID, uuidstr);
@@ -397,7 +397,7 @@ open_worktree(struct got_worktree **worktree, const char *path)
goto done;
uuid_from_string(uuidstr, &(*worktree)->uuid, &uuid_status);
if (uuid_status != uuid_s_ok) {
- err = got_error_uuid(uuid_status);
+ err = got_error_uuid(uuid_status, "uuid_from_string");
goto done;
}
@@ -1455,7 +1455,7 @@ get_ref_name(char **refname, struct got_worktree *worktree, const char *prefix)
uuid_to_string(&worktree->uuid, &uuidstr, &uuid_status);
if (uuid_status != uuid_s_ok)
- return got_error_uuid(uuid_status);
+ return got_error_uuid(uuid_status, "uuid_to_string");
if (asprintf(refname, "%s-%s", prefix, uuidstr)
== -1) {