]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
Fix reading harddisk serials.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Feb 2014 16:32:04 +0000 (17:32 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Feb 2014 16:32:04 +0000 (17:32 +0100)
It was falsely assumed that the harddisk serial is terminated
by NULL. This is not the case, so we initialize the memory
with zeros and copy only 20 bytes.

src/_fireinfo/fireinfo.c

index 4ab2bfad7083aa61275037c3d5b55cc36766626f..fc639d9d4cd904ec03e6a41e71313ce030098fe9 100644 (file)
@@ -209,7 +209,9 @@ do_get_harddisk_serial(PyObject *o, PyObject *args) {
 
        if (!ioctl(fd, HDIO_GET_IDENTITY, &hd)) {
                char serial[21];
-               strncpy(serial, (const char *)hd.serial_no, sizeof(serial));
+               memset(serial, 0, sizeof(serial));
+
+               strncpy(serial, (const char *)hd.serial_no, sizeof(serial) - 1);
 
                if (serial[0])
                        return PyString_FromString(serial);