AmendHub

Download:

jcs

/

subtext

/

amendments

/

351

zmodem: Handle malloc failure


jcs made amendment 351 about 1 year ago
--- zmodem.c Mon Nov 7 11:51:48 2022 +++ zmodem.c Wed Mar 1 23:16:00 2023 @@ -243,7 +243,9 @@ ZCreateSender(struct session *session, FILE *fp, char if (!fp) return NULL; - zs = xmalloczero(sizeof(struct zmodem_session), "ZCreateSender"); + zs = xmalloczero(sizeof(struct zmodem_session)); + if (zs == NULL) + return NULL; zs->session = session; zs->file = fp; strlcpy(zs->file_name, file_name, sizeof(zs->file_name)); @@ -263,11 +265,17 @@ ZCreateReceiver(struct session *session, char *path) { struct zmodem_session *zs; - zs = xmalloczero(sizeof(struct zmodem_session), "ZCreateReceiver"); + zs = xmalloczero(sizeof(struct zmodem_session)); + if (zs == NULL) + return NULL; zs->session = session; zs->ZMode = IdZAutoR; - zs->upload_file_path = xstrdup(path, "zmodem path"); - + zs->upload_file_path = xstrdup(path); + if (zs->upload_file_path == NULL) { + xfree(&zs); + return NULL; + } + return zs; }