summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auth.c23
-rw-r--r--info.c6
-rw-r--r--lock.c19
-rw-r--r--popup.c4
-rw-r--r--remote.c20
-rw-r--r--restart.c26
-rw-r--r--save.c4
-rw-r--r--saveutil.c13
-rw-r--r--xsm.c5
9 files changed, 63 insertions, 57 deletions
diff --git a/auth.c b/auth.c
index 67f0eca..da2cbb6 100644
--- a/auth.c
+++ b/auth.c
@@ -95,13 +95,11 @@ unique_filename(char *path, char *prefix, int *pFd)
char tempFile[PATH_MAX];
char *tmp;
- sprintf (tempFile, "%s/%sXXXXXX", path, prefix);
+ snprintf (tempFile, sizeof(tempFile), "%s/%sXXXXXX", path, prefix);
tmp = (char *) mktemp (tempFile);
if (tmp)
{
- char *ptr = (char *) malloc (strlen (tmp) + 1);
- strcpy (ptr, tmp);
- return (ptr);
+ return strdup(tmp);
}
else
return (NULL);
@@ -110,11 +108,10 @@ unique_filename(char *path, char *prefix, int *pFd)
char tempFile[PATH_MAX];
char *ptr;
- sprintf (tempFile, "%s/%sXXXXXX", path, prefix);
- ptr = (char *)malloc(strlen(tempFile) + 1);
+ snprintf (tempFile, sizeof(tempFile), "%s/%sXXXXXX", path, prefix);
+ ptr = strdup(tempFile);
if (ptr != NULL)
{
- strcpy(ptr, tempFile);
*pFd = mkstemp(ptr);
}
return ptr;
@@ -216,10 +213,10 @@ SetAuthentication(int count, IceListenObj *listenObjs,
umask (original_umask);
- sprintf (command, "iceauth source %s", addAuthFile);
+ snprintf (command, sizeof(command), "iceauth source %s", addAuthFile);
execute_system_command (command);
- unlink (addAuthFile);
+ remove (addAuthFile);
return (1);
@@ -233,12 +230,12 @@ SetAuthentication(int count, IceListenObj *listenObjs,
if (addAuthFile)
{
- unlink (addAuthFile);
+ remove (addAuthFile);
free (addAuthFile);
}
if (remAuthFile)
{
- unlink (remAuthFile);
+ remove (remAuthFile);
free (remAuthFile);
}
@@ -267,10 +264,10 @@ FreeAuthenticationData(int count, IceAuthDataEntry *authDataEntries)
XtFree ((char *) authDataEntries);
- sprintf (command, "iceauth source %s", remAuthFile);
+ snprintf (command, sizeof(command), "iceauth source %s", remAuthFile);
execute_system_command (command);
- unlink (remAuthFile);
+ remove (remAuthFile);
free (addAuthFile);
free (remAuthFile);
diff --git a/info.c b/info.c
index f6e0b74..a560623 100644
--- a/info.c
+++ b/info.c
@@ -165,7 +165,7 @@ DisplayProps(ClientRec *client)
AppendStr (&buffer, pprop->type);
AppendStr (&buffer, "\n");
AppendStr (&buffer, "Num values: ");
- sprintf (number, "%d", ListCount (pprop->values));
+ snprintf (number, sizeof(number), "%d", ListCount (pprop->values));
AppendStr (&buffer, number);
AppendStr (&buffer, "\n");
@@ -181,7 +181,7 @@ DisplayProps(ClientRec *client)
value = *card8;
AppendStr (&buffer, "Value 1: ");
- sprintf (number, "%d", value);
+ snprintf (number, sizeof(number), "%d", value);
AppendStr (&buffer, number);
if (strcmp (pprop->name, SmRestartStyleHint) == 0)
@@ -208,7 +208,7 @@ DisplayProps(ClientRec *client)
pval = (PropValue *) pj->thing;
AppendStr (&buffer, "Value ");
- sprintf (number, "%d", propnum);
+ snprintf (number, sizeof(number), "%d", propnum);
AppendStr (&buffer, number);
AppendStr (&buffer, ": ");
AppendStr (&buffer, (char *) pval->value);
diff --git a/lock.c b/lock.c
index f4d3848..3170458 100644
--- a/lock.c
+++ b/lock.c
@@ -59,10 +59,13 @@ LockSession(char *session_name, Bool write_id)
path = GetPath ();
#ifndef __UNIXOS2__
- sprintf (lock_file, "%s/.XSMlock-%s", path, session_name);
- sprintf (temp_lock_file, "%s/.XSMtlock-%s", path, session_name);
+ snprintf (lock_file, sizeof(lock_file), "%s/.XSMlock-%s",
+ path, session_name);
+ snprintf (temp_lock_file, sizeof(temp_lock_file), "%s/.XSMtlock-%s",
+ path, session_name);
#else
- sprintf (temp_lock_file, "%s/%s.slk", path, session_name);
+ snprintf (temp_lock_file, sizeof(temp_lock_file), "%s/%s.slk",
+ path, session_name);
#endif
if ((fd = creat (temp_lock_file, 0444)) < 0)
@@ -84,7 +87,7 @@ LockSession(char *session_name, Bool write_id)
if (link (temp_lock_file, lock_file) < 0)
status = 0;
- if (unlink (temp_lock_file) < 0)
+ if (remove (temp_lock_file) < 0)
status = 0;
#else
status = 0;
@@ -102,9 +105,10 @@ UnlockSession(char *session_name)
path = GetPath ();
- sprintf (lock_file, "%s/.XSMlock-%s", path, session_name);
+ snprintf (lock_file, sizeof(lock_file), "%s/.XSMlock-%s",
+ path, session_name);
- unlink (lock_file);
+ remove (lock_file);
}
@@ -119,7 +123,8 @@ GetLockId(char *session_name)
path = GetPath ();
- sprintf (lock_file, "%s/.XSMlock-%s", path, session_name);
+ snprintf (lock_file, sizeof(lock_file), "%s/.XSMlock-%s",
+ path, session_name);
if ((fp = fopen (lock_file, "r")) == NULL)
{
diff --git a/popup.c b/popup.c
index e03ac88..5c0ef97 100644
--- a/popup.c
+++ b/popup.c
@@ -88,7 +88,7 @@ PopupPopup(Widget parent, Widget popup, Bool transient, Bool first_time,
}
else
{
- sprintf (geom, "+%d+%d", popup_x, popup_y);
+ snprintf (geom, sizeof(geom), "+%d+%d", popup_x, popup_y);
XtVaSetValues (popup,
XtNgeometry, geom,
@@ -160,7 +160,7 @@ PopupPopup(Widget parent, Widget popup, Bool transient, Bool first_time,
XtUnrealizeWidget (popup);
- sprintf (geom, "+%d+%d", popup_x, popup_y);
+ snprintf (geom, sizeof(geom), "+%d+%d", popup_x, popup_y);
XtVaSetValues (popup,
XtNgeometry, geom,
diff --git a/remote.c b/remote.c
index f161f96..52df33e 100644
--- a/remote.c
+++ b/remote.c
@@ -70,8 +70,9 @@ remote_start(char *restart_protocol, char *restart_machine, char *program,
if (pipe (pipefd) < 0)
{
- sprintf (msg, "%s: pipe() error during remote start of %s",
- Argv[0], program);
+ snprintf (msg, sizeof(msg),
+ "%s: pipe() error during remote start of %s",
+ Argv[0], program);
add_log_text (msg);
perror (msg);
}
@@ -81,8 +82,9 @@ remote_start(char *restart_protocol, char *restart_machine, char *program,
{
case -1:
- sprintf (msg, "%s: fork() error during remote start of %s",
- Argv[0], program);
+ snprintf (msg, sizeof(msg),
+ "%s: fork() error during remote start of %s",
+ Argv[0], program);
add_log_text (msg);
perror (msg);
break;
@@ -96,9 +98,9 @@ remote_start(char *restart_protocol, char *restart_machine, char *program,
execlp (RSHCMD, restart_machine, "rstartd", (char *) 0);
- sprintf (msg,
- "%s: execlp() of rstartd failed for remote start of %s",
- Argv[0], program);
+ snprintf (msg, sizeof(msg),
+ "%s: execlp() of rstartd failed for remote start of %s",
+ Argv[0], program);
perror (msg);
/*
* TODO : We would like to send this log information to the
@@ -228,8 +230,8 @@ format_rstart_env(char *str)
{
if (!isgraph (*temp) || *temp == '\\')
{
- char octal[3];
- sprintf (octal, "%o", *temp);
+ char octal[4];
+ snprintf (octal, sizeof(octal), "%o", *temp);
*(ptr++) = '\\';
for (i = 0; i < (3 - (int) strlen (octal)); i++)
*(ptr++) = '0';
diff --git a/restart.c b/restart.c
index 896d8d4..10e9ba3 100644
--- a/restart.c
+++ b/restart.c
@@ -247,7 +247,7 @@ Restart(int flag)
* The client is being restarted on the local machine.
*/
- sprintf (logtext, "Restarting locally : ");
+ snprintf (logtext, sizeof(logtext), "Restarting locally : ");
for (pp = args; *pp; pp++)
{
strcat (logtext, *pp);
@@ -259,8 +259,8 @@ Restart(int flag)
switch(fork()) {
case -1:
- sprintf (logtext,
- "%s: Can't fork() %s", Argv[0], program);
+ snprintf (logtext, sizeof(logtext),
+ "%s: Can't fork() %s", Argv[0], program);
add_log_text (logtext);
perror (logtext);
break;
@@ -268,8 +268,8 @@ Restart(int flag)
chdir(cwd);
if(env) environ = env;
execvp(program, args);
- sprintf (logtext, "%s: Can't execvp() %s",
- Argv[0], program);
+ snprintf (logtext, sizeof(logtext),
+ "%s: Can't execvp() %s", Argv[0], program);
perror (logtext);
/*
* TODO : We would like to send this log information to the
@@ -296,8 +296,8 @@ Restart(int flag)
* The client is being restarted on a remote machine.
*/
- sprintf (logtext, "Restarting remotely on %s : ",
- restart_machine);
+ snprintf (logtext, sizeof(logtext),
+ "Restarting remotely on %s : ", restart_machine);
for (pp = args; *pp; pp++)
{
strcat (logtext, *pp);
@@ -447,7 +447,8 @@ Clone(ClientRec *client, Bool useSavedState)
switch(fork()) {
case -1:
- sprintf (msg, "%s: Can't fork() %s", Argv[0], program);
+ snprintf (msg, sizeof(msg),
+ "%s: Can't fork() %s", Argv[0], program);
add_log_text (msg);
perror (msg);
break;
@@ -455,7 +456,8 @@ Clone(ClientRec *client, Bool useSavedState)
chdir(cwd);
if(env) environ = env;
execvp(program, args);
- sprintf (msg, "%s: Can't execvp() %s", Argv[0], program);
+ snprintf (msg, sizeof(msg),
+ "%s: Can't execvp() %s", Argv[0], program);
perror (msg);
/*
* TODO : We would like to send this log information to the
@@ -528,7 +530,7 @@ StartDefaultApps (void)
home = (char *) getenv ("HOME");
if (!home)
home = ".";
- sprintf (filename, "%s/.xsmstartup", home);
+ snprintf (filename, sizeof(filename), "%s/.xsmstartup", home);
f = fopen (filename, "r");
@@ -556,7 +558,7 @@ StartDefaultApps (void)
if ((p = strchr (buf, '\n')))
*p = '\0';
- sprintf (logtext, "Starting locally : %s\n", buf);
+ snprintf (logtext, sizeof(logtext), "Starting locally : %s\n", buf);
add_log_text (logtext);
len = strlen (buf);
@@ -589,7 +591,7 @@ StartNonSessionAwareApps(void)
* byte for this.
*/
- sprintf (logtext, "Restarting locally : %s\n",
+ snprintf (logtext, sizeof(logtext), "Restarting locally : %s\n",
non_session_aware_clients[i]);
add_log_text (logtext);
diff --git a/save.c b/save.c
index 5d06877..229a6d7 100644
--- a/save.c
+++ b/save.c
@@ -147,7 +147,7 @@ MakeCurrentSession(String new_name, Bool name_changed)
LockSession (session_name, True);
- sprintf (title, "xsm: %s", session_name);
+ snprintf (title, sizeof(title), "xsm: %s", session_name);
XtVaSetValues (topLevel,
XtNtitle, title,
@@ -413,7 +413,7 @@ SaveOkXtProc(Widget w, XtPointer client_data, XtPointer callData)
{
name_locked = True;
- sprintf (label, "Another session by the name '%s' is active.\nChoose another name for the session.", name);
+ snprintf (label, sizeof(label), "Another session by the name '%s' is active.\nChoose another name for the session.", name);
XtUnmanageChild (nameInUseOverwriteButton);
diff --git a/saveutil.c b/saveutil.c
index 0e81785..cd020dd 100644
--- a/saveutil.c
+++ b/saveutil.c
@@ -47,9 +47,8 @@ set_session_save_file_name(char *session_name)
p = ".";
}
- strcpy (session_save_file, p);
- strcat (session_save_file, "/.XSM-");
- strcat (session_save_file, session_name);
+ snprintf (session_save_file, sizeof(session_save_file),
+ "%s/.XSM-%s", p, session_name);
}
@@ -314,8 +313,8 @@ WriteSave(char *sm_id)
{
char msg[256];
- sprintf (msg, "%s: Error creating session save file %s",
- Argv[0], session_save_file);
+ snprintf (msg, sizeof(msg), "%s: Error creating session save file %s",
+ Argv[0], session_save_file);
add_log_text (msg);
perror (msg);
}
@@ -426,7 +425,7 @@ DeleteSession(char *session_name)
dir = ".";
}
- sprintf (filename, "%s/.XSM-%s", dir, session_name);
+ snprintf (filename, sizeof(filename), "%s/.XSM-%s", dir, session_name);
f = fopen(filename, "r");
if(!f) {
@@ -510,7 +509,7 @@ DeleteSession(char *session_name)
if (buf)
free (buf);
- return ((unlink (filename) == -1) ? 0 : 1);
+ return ((remove (filename) == -1) ? 0 : 1);
}
diff --git a/xsm.c b/xsm.c
index 15304ba..4a95bd2 100644
--- a/xsm.c
+++ b/xsm.c
@@ -358,7 +358,8 @@ SetWM_DELETE_WINDOW(Widget widget, String delAction)
{
char translation[64];
- sprintf (translation, "<Message>WM_PROTOCOLS: %s", delAction);
+ snprintf (translation, sizeof(translation),
+ "<Message>WM_PROTOCOLS: %s", delAction);
XtOverrideTranslations (widget, XtParseTranslationTable (translation));
XSetWMProtocols (XtDisplay(widget), XtWindow (widget),
@@ -495,7 +496,7 @@ StartSession(char *name, Bool use_default)
* Set the main window's title to the session name.
*/
- sprintf (title, "xsm: %s", name);
+ snprintf (title, sizeof(title), "xsm: %s", name);
XtVaSetValues (topLevel,
XtNtitle, title, /* session name */