diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-07-17 10:06:05 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-07-17 10:19:54 -0700 |
commit | 83f33926d43f6ae4cf9734e3aedbef23fb0d6b74 (patch) | |
tree | 7c934b100e3ce9b1b3ec8cb597a7fff92a198fba | |
parent | 3db78d0fa60e07a4ffda61a19849ad30623f70cf (diff) |
XauReadAuth: move failure handling code to a common code block
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | AuRead.c | 55 |
1 files changed, 28 insertions, 27 deletions
@@ -73,43 +73,44 @@ read_counted_string (unsigned short *countp, char **stringp, FILE *file) Xauth * XauReadAuth (FILE *auth_file) { - Xauth local; + Xauth local = { 0, 0, NULL, 0, NULL, 0, NULL, 0, NULL }; Xauth *ret; - if (read_short (&local.family, auth_file) == 0) - return NULL; - if (read_counted_string (&local.address_length, &local.address, auth_file) == 0) - return NULL; - if (read_counted_string (&local.number_length, &local.number, auth_file) == 0) { - free (local.address); - return NULL; + if (read_short (&local.family, auth_file) == 0) { + goto fail; + } + if (read_counted_string (&local.address_length, &local.address, auth_file) + == 0) { + goto fail; + } + if (read_counted_string (&local.number_length, &local.number, auth_file) + == 0) { + goto fail; } if (read_counted_string (&local.name_length, &local.name, auth_file) == 0) { - free (local.address); - free (local.number); - return NULL; + goto fail; } if (read_counted_string (&local.data_length, &local.data, auth_file) == 0) { - free (local.address); - free (local.number); - free (local.name); - return NULL; + goto fail; } ret = malloc (sizeof (Xauth)); - if (!ret) { - free (local.address); - free (local.number); - free (local.name); - if (local.data) { + if (ret == NULL) { + goto fail; + } + *ret = local; + return ret; + + fail: + free (local.address); + free (local.number); + free (local.name); + if (local.data) { #ifdef HAVE_EXPLICIT_BZERO - explicit_bzero (local.data, local.data_length); + explicit_bzero (local.data, local.data_length); #else - bzero (local.data, local.data_length); + bzero (local.data, local.data_length); #endif - free (local.data); - } - return NULL; + free (local.data); } - *ret = local; - return ret; + return NULL; } |