summaryrefslogtreecommitdiffstats
path: root/src/dmidecodemodule.c
diff options
context:
space:
mode:
authornima <nima@abc39116-655e-4be6-ad55-d661dc543056>2008-12-19 13:21:24 +0000
committernima <nima@abc39116-655e-4be6-ad55-d661dc543056>2008-12-19 13:21:24 +0000
commit11ec71fe19b72a35612fa52cef5c25760e487d7d (patch)
tree51908a8cb1ea1d89a32284c73fcc9e035062c37b /src/dmidecodemodule.c
parentb007b775afdba38cdc3430ec9c909324d3522fb4 (diff)
downloadpython-dmidecode-11ec71fe19b72a35612fa52cef5c25760e487d7d.tar.gz
python-dmidecode-11ec71fe19b72a35612fa52cef5c25760e487d7d.tar.xz
python-dmidecode-11ec71fe19b72a35612fa52cef5c25760e487d7d.zip
Check that the path given with set_dev() is writeable.
Don't crash when writing to a read-only file, return False instead. Missing an INCREF in get_dev() fixed. git-svn-id: svn://svn.autonomy.net.au/python-dmidecode@124 abc39116-655e-4be6-ad55-d661dc543056
Diffstat (limited to 'src/dmidecodemodule.c')
-rw-r--r--src/dmidecodemodule.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/dmidecodemodule.c b/src/dmidecodemodule.c
index 8aec347..a37344d 100644
--- a/src/dmidecodemodule.c
+++ b/src/dmidecodemodule.c
@@ -158,25 +158,38 @@ static PyObject* dmidecode_get_type(PyObject *self, PyObject *args) {
}
static PyObject* dmidecode_dump(PyObject *self, PyObject *args) {
- if(access(opt.dumpfile, W_OK) == 0)
+ const char *f = PyString_AsString(opt.dumpfile);
+ if((access(f, F_OK) != 0) || (access(f, W_OK) == 0))
if(dump(PyString_AS_STRING(opt.dumpfile)))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject* dmidecode_get_dev(PyObject *self, PyObject *null) {
- if(opt.dumpfile != NULL) return opt.dumpfile;
- else return PyString_FromString(opt.devmem);
+ PyObject *dev;
+ if(opt.dumpfile != NULL) dev = opt.dumpfile;
+ else dev = PyString_FromString(opt.devmem);
+ Py_INCREF(dev);
+ return dev;
}
static PyObject* dmidecode_set_dev(PyObject *self, PyObject *arg) {
if(PyString_Check(arg)) {
- if(opt.dumpfile) { Py_DECREF(opt.dumpfile); }
- opt.dumpfile = arg;
- Py_INCREF(opt.dumpfile);
- Py_RETURN_TRUE;
- } else Py_RETURN_FALSE;
- //PyErr_Occurred()
+ if(opt.dumpfile == arg) Py_RETURN_TRUE;
+
+ struct stat buf;
+ char *f = PyString_AsString(arg);
+ stat(f, &buf);
+ if(!S_ISDIR(buf.st_mode)) {
+ if(opt.dumpfile)
+ Py_DECREF(opt.dumpfile);
+ opt.dumpfile = arg;
+ Py_INCREF(opt.dumpfile);
+ Py_RETURN_TRUE;
+ }
+ }
+ Py_RETURN_FALSE;
+ //PyErr_Occurred();
}