#1071 Possible resource leak in create_mail_spool()
Closed: Fixed None Opened 9 years ago by sgallagh.

406int create_mail_spool(TALLOC_CTX *mem_ctx,
407                      const char *username,
408                      const char *maildir,
409                      uid_t uid, gid_t gid)
410{
411    char *spool_file = NULL;
412    int fd;
413    int ret;
414
415    spool_file = talloc_asprintf(mem_ctx, "%s/%s", maildir, username);
416    if (spool_file == NULL) {
417        ret = ENOMEM;
418        goto fail;
419    }
420
421    selinux_file_context(spool_file);
422
CID 11082: Resource leak (RESOURCE_LEAK)Calling opening function "open".
Assigning: "fd" = handle returned from "open(spool_file, 193, 0)".
423    fd = open(spool_file, O_CREAT | O_WRONLY | O_EXCL, 0);
At conditional (1): "fd < 0" taking the false branch.
424    if (fd < 0) {
425        ret = errno;
426        DEBUG(1, ("Cannot open() the spool file: [%d][%s]\n",
427                  ret, strerror(ret)));
428        goto fail;
429    }
430
Variable "fd" is not closed or saved in function "fchmod".
431    ret = fchmod(fd, 0600);
At conditional (2): "ret != 0" taking the true branch.
432    if (ret != 0) {
433        ret = errno;
At conditional (3): "1 <= debug_level" taking the true branch.
At conditional (4): "debug_timestamps" taking the true branch.
434        DEBUG(1, ("Cannot fchmod() the spool file: [%d][%s]\n",
435                  ret, strerror(ret)));
436        goto fail;
437    }
438
Variable "fd" is not closed or saved in function "fchown".
439    ret = fchown(fd, uid, gid);
440    if (ret != 0) {
441        ret = errno;
442        DEBUG(1, ("Cannot fchown() the spool file: [%d][%s]\n",
443                  ret, strerror(ret)));
444        goto fail;
445    }
446
Variable "fd" is not closed or saved in function "fsync".
447    ret = fsync(fd);
448    if (ret != 0) {
449        ret = errno;
450        DEBUG(1, ("Cannot fsync() the spool file: [%d][%s]\n",
451                  ret, strerror(ret)));
452        goto fail;
453    }
454
455    ret = close(fd);
456    if (ret != 0) {
457        ret = errno;
458        DEBUG(1, ("Cannot close() the spool file: [%d][%s]\n",
459                  ret, strerror(ret)));
460        goto fail;
461    }
462
463fail:
464    reset_selinux_file_context();
465    talloc_free(spool_file);
Handle variable "fd" going out of scope leaks the handle.
466    return ret;
467}
468

Fields changed

milestone: NEEDS_TRIAGE => SSSD 1.7.0

Fields changed

patch: 0 => 1
status: new => assigned

Fixed in: 5a66e8f

resolution: => fixed
status: assigned => closed

Fields changed

rhbz: => 0

Metadata Update from @sgallagh:
- Issue assigned to jzeleny
- Issue set to the milestone: SSSD 1.7.0

3 years ago

SSSD is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in SSSD's github repository.

This issue has been cloned to Github and is available here:
- https://github.com/SSSD/sssd/issues/2113

If you want to receive further updates on the issue, please navigate to the github issue
and click on subscribe button.

Thank you for understanding. We apologize for all inconvenience.

Login to comment on this ticket.

Metadata