Convert possibly-unsafe sprintf's to snprintf's.

This commit is contained in:
Tom Lane 2002-08-12 14:47:46 +00:00
parent b47c4ddc7f
commit 1ccc2451c6
4 changed files with 28 additions and 16 deletions

View File

@ -63,13 +63,15 @@ void *
BSD44_derived_dlopen(const char *file, int num)
{
#if defined(__mips__)
sprintf(error_message, "dlopen (%s) not supported", file);
snprintf(error_message, sizeof(error_message),
"dlopen (%s) not supported", file);
return NULL;
#else
void *vp;
if ((vp = dlopen((char *) file, num)) == (void *) NULL)
sprintf(error_message, "dlopen '%s' failed. (%s)", file, dlerror());
snprintf(error_message, sizeof(error_message),
"dlopen '%s' failed. (%s)", file, dlerror());
return vp;
#endif
}
@ -78,7 +80,8 @@ void *
BSD44_derived_dlsym(void *handle, const char *name)
{
#if defined(__mips__)
sprintf(error_message, "dlsym (%s) failed", name);
snprintf(error_message, sizeof(error_message),
"dlsym (%s) failed", name);
return NULL;
#else
void *vp;
@ -88,12 +91,13 @@ BSD44_derived_dlsym(void *handle, const char *name)
if (*name != '_')
{
sprintf(buf, "_%s", name);
snprintf(buf, sizeof(buf), "_%s", name);
name = buf;
}
#endif
if ((vp = dlsym(handle, (char *) name)) == (void *) NULL)
sprintf(error_message, "dlsym (%s) failed", name);
snprintf(error_message, sizeof(error_message),
"dlsym (%s) failed", name);
return vp;
#endif
}

View File

@ -63,13 +63,15 @@ void *
BSD44_derived_dlopen(const char *file, int num)
{
#if defined(__mips__)
sprintf(error_message, "dlopen (%s) not supported", file);
snprintf(error_message, sizeof(error_message),
"dlopen (%s) not supported", file);
return NULL;
#else
void *vp;
if ((vp = dlopen((char *) file, num)) == (void *) NULL)
sprintf(error_message, "dlopen (%s) failed", file);
snprintf(error_message, sizeof(error_message),
"dlopen (%s) failed", file);
return vp;
#endif
}
@ -78,7 +80,8 @@ void *
BSD44_derived_dlsym(void *handle, const char *name)
{
#if defined(__mips__)
sprintf(error_message, "dlsym (%s) failed", name);
snprintf(error_message, sizeof(error_message),
"dlsym (%s) failed", name);
return NULL;
#elif defined(__ELF__)
return dlsym(handle, name);
@ -88,11 +91,12 @@ BSD44_derived_dlsym(void *handle, const char *name)
if (*name != '_')
{
sprintf(buf, "_%s", name);
snprintf(buf, sizeof(buf), "_%s", name);
name = buf;
}
if ((vp = dlsym(handle, (char *) name)) == (void *) NULL)
sprintf(error_message, "dlsym (%s) failed", name);
snprintf(error_message, sizeof(error_message),
"dlsym (%s) failed", name);
return vp;
#endif
}

View File

@ -67,7 +67,7 @@ next_dlsym(void *handle, char *symbol)
char symbuf[1024];
unsigned long symref = 0;
sprintf(symbuf, "_%s", symbol);
snprintf(symbuf, sizeof(symbuf), "_%s", symbol);
if (!rld_lookup(errorStream, symbuf, &symref))
TransferError(errorStream);
CloseError(errorStream);

View File

@ -63,13 +63,15 @@ void *
BSD44_derived_dlopen(const char *file, int num)
{
#if defined(__mips__)
sprintf(error_message, "dlopen (%s) not supported", file);
snprintf(error_message, sizeof(error_message),
"dlopen (%s) not supported", file);
return NULL;
#else
void *vp;
if ((vp = dlopen((char *) file, num)) == (void *) NULL)
sprintf(error_message, "dlopen (%s) failed", file);
snprintf(error_message, sizeof(error_message),
"dlopen (%s) failed", file);
return vp;
#endif
}
@ -78,7 +80,8 @@ void *
BSD44_derived_dlsym(void *handle, const char *name)
{
#if defined(__mips__)
sprintf(error_message, "dlsym (%s) failed", name);
snprintf(error_message, sizeof(error_message),
"dlsym (%s) failed", name);
return NULL;
#elif defined(__ELF__)
return dlsym(handle, name);
@ -88,11 +91,12 @@ BSD44_derived_dlsym(void *handle, const char *name)
if (*name != '_')
{
sprintf(buf, "_%s", name);
snprintf(buf, sizeof(buf), "_%s", name);
name = buf;
}
if ((vp = dlsym(handle, (char *) name)) == (void *) NULL)
sprintf(error_message, "dlsym (%s) failed", name);
snprintf(error_message, sizeof(error_message),
"dlsym (%s) failed", name);
return vp;
#endif
}