summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/abrtlib.h9
-rw-r--r--lib/Plugins/CCpp.cpp10
-rw-r--r--lib/Plugins/Catcut.cpp4
-rw-r--r--lib/Plugins/FileTransfer.cpp4
-rw-r--r--lib/Plugins/Firefox.cpp8
-rw-r--r--lib/Plugins/Mailx.cpp2
-rw-r--r--lib/Plugins/SQLite3.cpp4
-rw-r--r--lib/Plugins/TicketUploader.cpp4
-rw-r--r--lib/Utils/CrashTypesSocket.cpp2
-rw-r--r--lib/Utils/Makefile.am1
-rw-r--r--lib/Utils/xatonum.cpp50
-rw-r--r--src/Daemon/Daemon.cpp6
-rw-r--r--src/Daemon/MiddleWare.cpp2
-rw-r--r--src/Daemon/PluginManager.cpp6
-rw-r--r--src/Daemon/Settings.cpp2
-rw-r--r--src/Hooks/CCpp.cpp27
16 files changed, 101 insertions, 40 deletions
diff --git a/inc/abrtlib.h b/inc/abrtlib.h
index 17bd5429..c5ca60f7 100644
--- a/inc/abrtlib.h
+++ b/inc/abrtlib.h
@@ -102,6 +102,15 @@ char* xstrndup(const char *s, int n);
char* skip_whitespace(const char *s);
char* skip_non_whitespace(const char *s);
+unsigned xatou(const char *numstr);
+int xatoi(const char *numstr);
+/* Using xatoi() instead of naive atoi() is not always convenient -
+ * in many places people want *non-negative* values, but store them
+ * in signed int. Therefore we need this one:
+ * dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc */
+int xatoi_u(const char *numstr);
+
+
extern ssize_t safe_read(int fd, void *buf, size_t count);
// NB: will return short read on error, not -1,
// if some data was read before error occurred
diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp
index 0fe3d32a..c9a31c7e 100644
--- a/lib/Plugins/CCpp.cpp
+++ b/lib/Plugins/CCpp.cpp
@@ -309,7 +309,7 @@ static void GetBacktrace(const char *pDebugDumpDir,
args[11] = (char*)"info sharedlib";
args[12] = NULL;
- ExecVP(args, atoi(UID.c_str()), pBacktrace);
+ ExecVP(args, xatoi_u(UID.c_str()), pBacktrace);
}
static void GetIndependentBuildIdPC(const char *unstrip_n_output,
@@ -355,7 +355,7 @@ static string run_unstrip_n(const char *pDebugDumpDir)
args[3] = NULL;
string output;
- ExecVP(args, atoi(UID.c_str()), output);
+ ExecVP(args, xatoi_u(UID.c_str()), output);
free(args[1]);
@@ -575,7 +575,7 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir)
close(pipeout[0]); /* read side of the pipe */
/* abrt-backtrace is executed under the user's uid and gid. */
- uid_t uid = atoi(uid_str.c_str());
+ uid_t uid = xatoi_u(uid_str.c_str());
struct passwd* pw = getpwuid(uid);
gid_t gid = pw ? pw->pw_gid : uid;
setgroups(1, &gid);
@@ -670,7 +670,7 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force)
dd.Close(); /* do not keep dir locked longer than needed */
string build_ids;
- if (m_bInstallDebugInfo && DebuginfoCheckPolkit(atoi(UID.c_str())))
+ if (m_bInstallDebugInfo && DebuginfoCheckPolkit(xatoi_u(UID.c_str())))
{
if (m_nDebugInfoCacheMB > 0)
{
@@ -761,7 +761,7 @@ void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings)
it = pSettings.find("DebugInfoCacheMB");
if (it != end)
{
- m_nDebugInfoCacheMB = atoi(it->second.c_str());
+ m_nDebugInfoCacheMB = xatou(it->second.c_str());
}
it = pSettings.find("InstallDebugInfo");
if (it == end) //compat, remove after 0.0.11
diff --git a/lib/Plugins/Catcut.cpp b/lib/Plugins/Catcut.cpp
index ebddfdd3..35f56f25 100644
--- a/lib/Plugins/Catcut.cpp
+++ b/lib/Plugins/Catcut.cpp
@@ -510,12 +510,12 @@ void CReporterCatcut::SetSettings(const map_plugin_settings_t& pSettings)
it = pSettings.find("RetryCount");
if (it != end)
{
- m_nRetryCount = atoi(it->second.c_str());
+ m_nRetryCount = xatoi_u(it->second.c_str());
}
it = pSettings.find("RetryDelay");
if (it != end)
{
- m_nRetryDelay = atoi(it->second.c_str());
+ m_nRetryDelay = xatoi_u(it->second.c_str());
}
}
diff --git a/lib/Plugins/FileTransfer.cpp b/lib/Plugins/FileTransfer.cpp
index c98645cf..08bba6ca 100644
--- a/lib/Plugins/FileTransfer.cpp
+++ b/lib/Plugins/FileTransfer.cpp
@@ -388,13 +388,13 @@ void CFileTransfer::SetSettings(const map_plugin_settings_t& pSettings)
it = pSettings.find("RetryCount");
if (it != end)
{
- m_nRetryCount = atoi(it->second.c_str());
+ m_nRetryCount = xatoi_u(it->second.c_str());
}
it = pSettings.find("RetryDelay");
if (it != end)
{
- m_nRetryDelay = atoi(it->second.c_str());
+ m_nRetryDelay = xatoi_u(it->second.c_str());
}
it = pSettings.find("ArchiveType");
diff --git a/lib/Plugins/Firefox.cpp b/lib/Plugins/Firefox.cpp
index bcc59485..2bb7f9c5 100644
--- a/lib/Plugins/Firefox.cpp
+++ b/lib/Plugins/Firefox.cpp
@@ -281,7 +281,7 @@ static void GetBacktrace(const char *pDebugDumpDir, std::string& pBacktrace)
args[9] = (char*)"thread apply all backtrace full";
args[10] = NULL;
- ExecVP(args, atoi(UID.c_str()), pBacktrace);
+ ExecVP(args, xatoi_u(UID.c_str()), pBacktrace);
free(args[5]);
free(args[7]);
@@ -454,7 +454,7 @@ static std::string run_unstrip_n(const char *pDebugDumpDir)
args[3] = NULL;
std::string output;
- ExecVP(args, atoi(UID.c_str()), output);
+ ExecVP(args, xatoi_u(UID.c_str()), output);
free(args[1]);
@@ -886,7 +886,7 @@ void CAnalyzerFirefox::CreateReport(const char *pDebugDumpDir, int force)
dd.Close(); /* do not keep dir locked longer than needed */
std::string build_ids;
- if (m_bInstallDebugInfo && DebuginfoCheckPolkit(atoi(UID.c_str()))) {
+ if (m_bInstallDebugInfo && DebuginfoCheckPolkit(xatoi_u(UID.c_str()))) {
if (m_nDebugInfoCacheMB > 0)
trim_debuginfo_cache(m_nDebugInfoCacheMB);
InstallDebugInfos(pDebugDumpDir, build_ids);
@@ -974,7 +974,7 @@ void CAnalyzerFirefox::SetSettings(const map_plugin_settings_t& pSettings)
it = pSettings.find("DebugInfoCacheMB");
if (it != end)
{
- m_nDebugInfoCacheMB = atoi(it->second.c_str());
+ m_nDebugInfoCacheMB = xatou(it->second.c_str());
}
it = pSettings.find("InstallDebugInfo");
if (it == end) //compat, remove after 0.0.11
diff --git a/lib/Plugins/Mailx.cpp b/lib/Plugins/Mailx.cpp
index b06edebb..6904c169 100644
--- a/lib/Plugins/Mailx.cpp
+++ b/lib/Plugins/Mailx.cpp
@@ -163,7 +163,7 @@ std::string CMailx::Report(const map_crash_report_t& pCrashReport,
update_client(_("Sending an email..."));
const char *uid_str = pCrashReport.find(CD_MWUID)->second[CD_CONTENT].c_str();
- exec_and_feed_input(atoi(uid_str), emailBody.c_str(), args);
+ exec_and_feed_input(xatoi_u(uid_str), emailBody.c_str(), args);
while (*args)
{
diff --git a/lib/Plugins/SQLite3.cpp b/lib/Plugins/SQLite3.cpp
index c3f7a7d8..12f8a5db 100644
--- a/lib/Plugins/SQLite3.cpp
+++ b/lib/Plugins/SQLite3.cpp
@@ -198,9 +198,9 @@ static bool check_table(sqlite3 *db)
if (pos != string::npos)
{
string tableVersion = tableName.substr(pos + 2);
- if (atoi(tableVersion.c_str()) < ABRT_TABLE_VERSION)
+ if (xatoi_u(tableVersion.c_str()) < ABRT_TABLE_VERSION)
{
- update_from_old_ver(db, atoi(tableVersion.c_str()));
+ update_from_old_ver(db, xatoi_u(tableVersion.c_str()));
}
return true;
}
diff --git a/lib/Plugins/TicketUploader.cpp b/lib/Plugins/TicketUploader.cpp
index 06b6cde8..14f5e1d5 100644
--- a/lib/Plugins/TicketUploader.cpp
+++ b/lib/Plugins/TicketUploader.cpp
@@ -394,12 +394,12 @@ void CTicketUploader::SetSettings(const map_plugin_settings_t& pSettings)
it = pSettings.find("RetryCount");
if (it != end)
{
- m_nRetryCount = atoi(it->second.c_str());
+ m_nRetryCount = xatoi_u(it->second.c_str());
}
it = pSettings.find("RetryDelay");
if (it != end)
{
- m_nRetryDelay = atoi(it->second.c_str());
+ m_nRetryDelay = xatoi_u(it->second.c_str());
}
}
diff --git a/lib/Utils/CrashTypesSocket.cpp b/lib/Utils/CrashTypesSocket.cpp
index f16e2a9a..3525c6a5 100644
--- a/lib/Utils/CrashTypesSocket.cpp
+++ b/lib/Utils/CrashTypesSocket.cpp
@@ -114,7 +114,7 @@ static int get_number_from_string(const std::string& pMessage, int& len)
}
}
len = ii + 1;
- return atoi(sNumber.c_str());
+ return xatoi(sNumber.c_str());
}
//TODO: remove constant 4 and place it in a message
diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am
index 9618751a..4f6670b8 100644
--- a/lib/Utils/Makefile.am
+++ b/lib/Utils/Makefile.am
@@ -14,6 +14,7 @@ libABRTUtils_la_SOURCES = \
logging.cpp \
copyfd.cpp \
skip_whitespace.cpp \
+ xatonum.cpp \
popen_and_save_output.cpp \
stringops.cpp \
dirsize.cpp \
diff --git a/lib/Utils/xatonum.cpp b/lib/Utils/xatonum.cpp
new file mode 100644
index 00000000..b096ca89
--- /dev/null
+++ b/lib/Utils/xatonum.cpp
@@ -0,0 +1,50 @@
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
+ *
+ * Licensed under GPLv2, see file LICENSE in this tarball for details.
+ */
+#include "abrtlib.h"
+
+unsigned xatou(const char *numstr)
+{
+ unsigned r;
+ int old_errno;
+ char *e;
+
+ if (*numstr < '0' || *numstr > '9')
+ goto inval;
+
+ old_errno = errno;
+ errno = 0;
+ r = strtoul(numstr, &e, 10);
+ if (errno || numstr == e || *e != '\0')
+ goto inval; /* error / no digits / illegal trailing chars */
+ errno = old_errno; /* Ok. So restore errno. */
+ return r;
+
+ inval:
+ error_msg_and_die("invalid number '%s'", numstr);
+}
+
+int xatoi_u(const char *numstr)
+{
+ unsigned r = xatou(numstr);
+ if (r > (unsigned)INT_MAX)
+ error_msg_and_die("invalid number '%s'", numstr);
+ return r;
+}
+
+int xatoi(const char *numstr)
+{
+ unsigned r;
+
+ if (*numstr != '-')
+ return xatoi_u(numstr);
+
+ r = xatou(numstr + 1);
+ if (r > (unsigned)INT_MAX + 1)
+ error_msg_and_die("invalid number '%s'", numstr);
+ return - (int)r;
+}
diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp
index 153363d5..db55f849 100644
--- a/src/Daemon/Daemon.cpp
+++ b/src/Daemon/Daemon.cpp
@@ -216,14 +216,14 @@ static int SetUpCron()
std::string sM = "";
sH = it_c->first.substr(0, pos);
- nH = atoi(sH.c_str());
+ nH = xatou(sH.c_str());
nH = nH > 23 ? 23 : nH;
nH = nH < 0 ? 0 : nH;
nM = nM > 59 ? 59 : nM;
nM = nM < 0 ? 0 : nM;
timeout += nH * 60 * 60;
sM = it_c->first.substr(pos + 1);
- nM = atoi(sM.c_str());
+ nM = xatou(sM.c_str());
timeout += nM * 60;
}
else
@@ -231,7 +231,7 @@ static int SetUpCron()
std::string sS = "";
sS = it_c->first;
- nS = atoi(sS.c_str());
+ nS = xatou(sS.c_str());
nS = nS <= 0 ? 1 : nS;
timeout = nS;
}
diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp
index eb60ce44..fd2e86bb 100644
--- a/src/Daemon/MiddleWare.cpp
+++ b/src/Daemon/MiddleWare.cpp
@@ -477,7 +477,7 @@ report_status_t Report(const map_crash_report_t& pCrashReport,
if (pUID != "")
{
- home = get_home_dir(atoi(pUID.c_str()));
+ home = get_home_dir(xatoi_u(pUID.c_str()));
if (home != "")
{
oldSettings = reporter->GetSettings();
diff --git a/src/Daemon/PluginManager.cpp b/src/Daemon/PluginManager.cpp
index 82f22e85..b6a8b154 100644
--- a/src/Daemon/PluginManager.cpp
+++ b/src/Daemon/PluginManager.cpp
@@ -391,7 +391,7 @@ void CPluginManager::SetPluginSettings(const char *pName,
return;
}
- std::string home = get_home_dir(atoi(pUID.c_str()));
+ std::string home = get_home_dir(xatoi_u(pUID.c_str()));
if (home == "")
{
return;
@@ -399,7 +399,7 @@ void CPluginManager::SetPluginSettings(const char *pName,
std::string confDir = home + "/.abrt";
std::string confPath = confDir + "/" + pName + "."PLUGINS_CONF_EXTENSION;
- uid_t uid = atoi(pUID.c_str());
+ uid_t uid = xatoi_u(pUID.c_str());
struct passwd* pw = getpwuid(uid);
gid_t gid = pw ? pw->pw_gid : uid;
@@ -461,7 +461,7 @@ map_plugin_settings_t CPluginManager::GetPluginSettings(const char *pName,
/*
if (abrt_plugin->second->GetType() == REPORTER)
{
- std::string home = get_home_dir(atoi(pUID.c_str()));
+ std::string home = get_home_dir(xatoi_u(pUID.c_str()));
if (home != "")
{
LoadPluginSettings(home + "/.abrt/" + pName + "."PLUGINS_CONF_EXTENSION, ret);
diff --git a/src/Daemon/Settings.cpp b/src/Daemon/Settings.cpp
index 327851f5..d89bebfd 100644
--- a/src/Daemon/Settings.cpp
+++ b/src/Daemon/Settings.cpp
@@ -176,7 +176,7 @@ static void ParseCommon()
it = s_mapSectionCommon.find("MaxCrashReportsSize");
if (it != end)
{
- g_settings_nMaxCrashReportsSize = atoi(it->second.c_str());
+ g_settings_nMaxCrashReportsSize = xatoi_u(it->second.c_str());
}
it = s_mapSectionCommon.find("ActionsAndReporters");
if (it != end)
diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp
index fd789cfb..e38c4f75 100644
--- a/src/Hooks/CCpp.cpp
+++ b/src/Hooks/CCpp.cpp
@@ -202,25 +202,26 @@ int main(int argc, char** argv)
logmode = LOGMODE_SYSLOG;
const char* dddir = argv[1];
- pid_t pid = atoi(argv[2]);
+ pid_t pid = xatoi_u(argv[2]);
const char* signal_str = argv[3];
- int signal = atoi(argv[3]);
- uid_t uid = atoi(argv[4]);
-
- if (signal != SIGQUIT
- && signal != SIGILL
- && signal != SIGABRT
- && signal != SIGFPE
- && signal != SIGSEGV
+ int signal_no = xatoi_u(argv[3]);
+ uid_t uid = xatoi_u(argv[4]);
+
+ if (signal_no != SIGQUIT
+ && signal_no != SIGILL
+ && signal_no != SIGABRT
+ && signal_no != SIGFPE
+ && signal_no != SIGSEGV
) {
/* not an error, exit silently */
return 0;
}
- if (pid <= 0 || (int)uid < 0)
+ if (pid <= 0)
{
- error_msg_and_die("pid '%s' or uid '%s' are bogus", argv[2], argv[4]);
+ error_msg_and_die("pid '%s' is bogus", argv[2]);
}
+
char *user_pwd = get_cwd(pid); /* may be NULL on error */
int core_fd = STDIN_FILENO;
@@ -299,7 +300,7 @@ int main(int argc, char** argv)
}
char* cmdline = get_cmdline(pid); /* never NULL */
- const char *signame = strsignal(atoi(signal_str));
+ const char *signame = strsignal(signal_no);
char *reason = xasprintf("Process was terminated by signal %s (%s)", signal_str, signame ? signame : signal_str);
snprintf(path, sizeof(path), "%s/ccpp-%ld-%u", dddir, (long)time(NULL), (int)pid);
@@ -388,7 +389,7 @@ int main(int argc, char** argv)
if (isdigit(*p))
/* x1.25: go a bit up, so that usual in-daemon trimming
* kicks in first, and we don't "fight" with it. */
- setting_MaxCrashReportsSize = (unsigned long)atoi(p) * 5 / 4;
+ setting_MaxCrashReportsSize = (unsigned long)xatou(p) * 5 / 4;
continue;
}
#undef DIRECTIVE