Skip to content
This repository was archived by the owner on Feb 24, 2024. It is now read-only.

Commit 9147b64

Browse files
committed
Replace asprintf with snprintf in kerberospw.c
asprintf is a gnu extension function. This commit replaces calls to this with a call to the standard snprintf function when reporting errors in the change_user_krb5pwd function.
1 parent 51a4c34 commit 9147b64

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/kerberospw.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,26 @@ int change_user_krb5pwd(
131131
}
132132
if (result_code) {
133133
char *message = NULL;
134-
bytes = asprintf(
135-
&message, "%.*s: %.*s",
136-
(int) result_code_string.length,
137-
(char *) result_code_string.data,
138-
(int) result_string.length,
139-
(char *) result_string.data
140-
);
141-
if (bytes == -1)
142-
{
134+
int msgSz = (int) result_code_string.length + (int) result_string.length
135+
+ 2 + 1;
136+
message = (char *)malloc(msgSz);
137+
if (message == NULL) {
143138
PyErr_NoMemory();
144139
}
145-
else
146-
{
147-
PyErr_SetObject(
148-
PwdChangeException_class,
149-
Py_BuildValue("((s:i))", message, result_code)
150-
);
151-
free(message);
140+
141+
if (message) {
142+
int rc = snprintf(message, msgSz, "%.*s: %.*s",
143+
(int) result_code_string.length,
144+
(char *) result_code_string.data,
145+
(int) result_string.length,
146+
(char *) result_string.data);
147+
if (rc > 0 && rc < = msgSz ) {
148+
PyErr_SetObject(
149+
PwdChangeException_class,
150+
Py_BuildValue("((s:i))", message, result_code)
151+
);
152+
free(message);
153+
}
152154
}
153155
goto end;
154156
}

0 commit comments

Comments
 (0)