summaryrefslogtreecommitdiffstats
path: root/Modules/syslogmodule.c
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-12-08 23:31:48 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-12-08 23:31:48 (GMT)
commite239d23e8cc66605f548585ad4489a8f12fc070d (patch)
treee165422c11006a4f3595742dd40a7a2095ef59ce /Modules/syslogmodule.c
parent1b2bd3b348d7bb861ae8c92853e5058766ebff80 (diff)
downloadcpython-e239d23e8cc66605f548585ad4489a8f12fc070d.zip
cpython-e239d23e8cc66605f548585ad4489a8f12fc070d.tar.gz
cpython-e239d23e8cc66605f548585ad4489a8f12fc070d.tar.bz2
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Diffstat (limited to 'Modules/syslogmodule.c')
-rw-r--r--Modules/syslogmodule.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c
index 1842dc9..5b86963 100644
--- a/Modules/syslogmodule.c
+++ b/Modules/syslogmodule.c
@@ -68,9 +68,9 @@ syslog_get_argv(void)
* is optional.
*/
- Py_ssize_t argv_len;
+ Py_ssize_t argv_len, scriptlen;
PyObject *scriptobj;
- char *atslash;
+ Py_UNICODE *atslash, *atstart;
PyObject *argv = PySys_GetObject("argv");
if (argv == NULL) {
@@ -90,13 +90,16 @@ syslog_get_argv(void)
if (!PyUnicode_Check(scriptobj)) {
return(NULL);
}
- if (PyUnicode_GET_SIZE(scriptobj) == 0) {
+ scriptlen = PyUnicode_GET_SIZE(scriptobj);
+ if (scriptlen == 0) {
return(NULL);
}
- atslash = strrchr(_PyUnicode_AsString(scriptobj), SEP);
+ atstart = PyUnicode_AS_UNICODE(scriptobj);
+ atslash = Py_UNICODE_strrchr(atstart, SEP);
if (atslash) {
- return(PyUnicode_FromString(atslash + 1));
+ return(PyUnicode_FromUnicode(atslash + 1,
+ scriptlen - (atslash - atstart) - 1));
} else {
Py_INCREF(scriptobj);
return(scriptobj);
@@ -113,6 +116,7 @@ syslog_openlog(PyObject * self, PyObject * args, PyObject *kwds)
long facility = LOG_USER;
PyObject *new_S_ident_o = NULL;
static char *keywords[] = {"ident", "logoption", "facility", 0};
+ char *ident = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|Ull:openlog", keywords, &new_S_ident_o, &logopt, &facility))
@@ -120,12 +124,12 @@ syslog_openlog(PyObject * self, PyObject * args, PyObject *kwds)
if (new_S_ident_o) {
Py_INCREF(new_S_ident_o);
- }
+ }
/* get sys.argv[0] or NULL if we can't for some reason */
if (!new_S_ident_o) {
new_S_ident_o = syslog_get_argv();
- }
+ }
Py_XDECREF(S_ident_o);
S_ident_o = new_S_ident_o;
@@ -134,8 +138,13 @@ syslog_openlog(PyObject * self, PyObject * args, PyObject *kwds)
* make a copy, and syslog(3) later uses it. We can't garbagecollect it
* If NULL, just let openlog figure it out (probably using C argv[0]).
*/
+ if (S_ident_o) {
+ ident = _PyUnicode_AsString(S_ident_o);
+ if (ident == NULL)
+ return NULL;
+ }
- openlog(S_ident_o ? _PyUnicode_AsString(S_ident_o) : NULL, logopt, facility);
+ openlog(ident, logopt, facility);
S_log_open = 1;
Py_INCREF(Py_None);