Fixes buffer overflows and --as-needed issues https://bugs.gentoo.org/show_bug.cgi?id=338936 Patch written by Kevin Pyle --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS = @CPPFLAGS@ @INTERLACE@ \ +AM_CPPFLAGS = @INTERLACE@ \ -DGLOBAL_BB=\"$(datadir)/bbtools/bbacpi.bb\" \ -DGLOBAL_NOBB=\"$(datadir)/bbtools/bbacpi.nobb\" \ -DGLOBAL_DATA=\"$(datadir)/bbtools\" --- a/bbacpi.cc +++ b/bbacpi.cc @@ -167,7 +167,7 @@ bool CheckLoad::checkbatteryfile (char* name, char* device) if (ret = (fp = fopen(name, "r"))) { char buffer[100]; char present[20]; - fgets(buffer,128,fp); + fgets(buffer, sizeof(buffer),fp); sscanf(buffer,"present: %s", present); if (strncmp(present, "yes", 3) != 0) { fprintf(stderr, "Device %s not present.\n", device); @@ -195,7 +195,7 @@ void CheckLoad::ReadStaticInfo() { /* Read data in any order */ found = 0; - while (found < 11 && (fgets(buffer, 63, fp) != NULL)) { + while (found < 11 && (fgets(buffer, sizeof(buffer), fp) != NULL)) { /* Present */ if (strncmp(buffer, "present:", 7) == 0 || strncmp(buffer, "Present:", 7) == 0) { @@ -277,7 +277,7 @@ void CheckLoad::ReadStaticInfo() { /* Read data in any order */ found = 0; - while (found < 11 && (fgets(buffer, 63, fp) != NULL)) { + while (found < 11 && (fgets(buffer, sizeof(buffer), fp) != NULL)) { /* Present */ if (strncmp(buffer, "present:", 7) == 0 || strncmp(buffer, "Present:", 7) == 0) { @@ -361,7 +361,7 @@ void CheckLoad::ReadStaticInfo() if ((fp = fopen(names.temptrip, "r"))) { found = 0; - while (found < 2 && (fgets(buffer,128,fp) != NULL)) { + while (found < 2 && (fgets(buffer, sizeof(buffer),fp) != NULL)) { /* Critical */ if (strncmp(buffer, "critical", 8) == 0 || strncmp(buffer, "Critical", 8) == 0) { @@ -425,7 +425,7 @@ void CheckLoad::Reconfigure() if (file_status.st_mtime != last_mtime) { found = 0; - while (found < 4 && (fgets(buffer, 63, fp) != NULL)) { + while (found < 4 && (fgets(buffer, sizeof(buffer), fp) != NULL)) { /* Charging state */ if (strncmp(buffer, "charging state:", 15) == 0 || strncmp(buffer, "Charging State:", 15) == 0) { @@ -463,7 +463,7 @@ void CheckLoad::Reconfigure() if (file_status.st_mtime != last_mtime) { found = 0; - while (found < 4 && (fgets(buffer, 63, fp) != NULL)) { + while (found < 4 && (fgets(buffer, sizeof(buffer), fp) != NULL)) { /* Charging state */ if (strncmp(buffer, "charging state:", 15) == 0 || strncmp(buffer, "Charging State:", 15) == 0) { @@ -497,7 +497,7 @@ void CheckLoad::Reconfigure() if ((fp = fopen(names.adapter, "r"))) { found = 0; - while (found < 1 && (fgets(buffer, 63,fp) != NULL)) { + while (found < 1 && (fgets(buffer, sizeof(buffer),fp) != NULL)) { if (strncmp(buffer, "state:", 6) == 0 || strncmp(buffer, "State:", 6) == 0) { sscanf(buffer+offset,"%s", adapter.state); @@ -511,7 +511,7 @@ void CheckLoad::Reconfigure() if ((fp = fopen(names.temperature, "r"))) { found = 0; - while (found < 1 && (fgets(buffer, 63,fp) != NULL)) { + while (found < 1 && (fgets(buffer, sizeof(buffer),fp) != NULL)) { if (strncmp(buffer, "temperature:", 12) == 0 || strncmp(buffer, "Temperature:", 12) == 0) { sscanf(buffer+offset,"%u", &temperature.celcius); --- a/configure.in +++ b/configure.in @@ -89,12 +89,12 @@ AC_PATH_XTRA CFLAGS="$CFLAGS $X_CFLAGS" CXXFLAGS="$CXXFLAGS $X_CFLAGS" -LDFLAGS="$LDFLAGS $X_LIBS $X_PRE_LIBS" +LIBS="$LIBS $X_LIBS $X_PRE_LIBS" dnl Checks for X libraries. -AC_CHECK_LIB(X11, XOpenDisplay, LDFLAGS="$LDFLAGS -lX11", +AC_CHECK_LIB(X11, XOpenDisplay,, AC_MSG_ERROR(XOpenDisplay not found in -lX11)) -LDFLAGS="$LDFLAGS $X_EXTRA_LIBS" +LIBS="$LIBS $X_EXTRA_LIBS" dnl Check for Imlib AC_MSG_CHECKING([for Imlib])