Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with MemoryError #12

Open
kernelzeroday opened this issue Jun 18, 2020 · 1 comment
Open

Crash with MemoryError #12

kernelzeroday opened this issue Jun 18, 2020 · 1 comment

Comments

@kernelzeroday
Copy link

Ran into this issue while testing the script. Worked fine a few times, then halfway through cleaning some logs i got a crash like this, then it continues to crash. IP and hostnames replaced as they are not relevant.

root@generic_host_name:~# python nojail.py -i x.x.x.x -n x.x.x.x
[ ] Cleaning logs for sjkgxd (x.x.x.x - x.x.x.x).
[ ] No entries to remove from /var/run/utmp.
[ ] No entries to remove from /var/log/wtmp.
[ ] No entries to remove from /var/log/btmp.
Traceback (most recent call last):
  File "nojail.py", line 601, in <module>
    clean_lastlog(LINUX_LASTLOG_FILE, args.user, args.ip, args.hostname)
  File "nojail.py", line 331, in clean_lastlog
    clean_file += f.read()
MemoryError

Any ideas? The system was nowhere close to out of memory.

Thanks

@JusticeRage
Copy link
Owner

Wow, the /var/log/lastlog file must be enormous to cause such an error. Would you be able to give me its approximate size?

Also, as I cannot reproduce this error on my end, could you apply the following patch and verify that:

  1. It solves the issue you have
  2. The lastlog update still works as intended?
--- a/nojail.py
+++ b/nojail.py
@@ -328,12 +328,15 @@ def clean_lastlog(filename, username, ip, hostname):
                                                              LAST_LOGIN["hostname"])

         # Append the rest of the file and overwrite lastlog:
-        clean_file += f.read()
         tmp_file = get_temp_filename()
         g = None
         try:
             g = open(tmp_file, "wb")
             g.write(clean_file)
+            lastlog_end = f.read(4096)
+            while lastlog_end:
+                g.write(lastlog_end)
+                lastlog_end = f.read(4096)
         finally:
             if g is not None:
                 g.close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants