1. Bill Garrison
  2. xar
  3. Issues
Issue #1 new

xar_err_new() fails to completely initialize the error structure

Bill Garrison
repo owner created an issue

Still in xar-105, xar_err_new() fails to completely initialize the error structure.

The xar errctx structure is defined as:

struct errctx {
    const char *str;
    int         saved_errno;
    xar_file_t  file;
    void       *usrctx;
    xar_t       x;

In the Apple source:

void xar_err_new(xar_t x) {
    memset(&XAR(x)->errctx, 0, sizeof(struct errctx));
    XAR(x)->errctx.saved_errno = errno;

xar_err_new() completely clears the archive's errctx structure and only sets the errctx.saved_errno field. But what happens if the caller has previously assigned a user context via the error handler?

The bug is that any previously assigned user context is assigned to the error, it is also cleared and never restored. If a user context has been assigned via xar_register_errhandler(), that user context is lost when xar_err_new() is called, which happens before any encountered xar err is reported to the callback.

One fix:

void xar_err_new(xar_t x) {
    void *savedUserContext = XAR(x)->errctx.usrctx;
    memset(&XAR(x)->errctx, 0, sizeof(struct errctx));
    XAR(x)->errctx.usrctx = savedUserContext;
    XAR(x)->errctx.saved_errno = errno;

Comments (0)

  1. Log in to comment