Allow compilation with -Werror, which is enabled by default in OpenEmbedded.

 -Wunused-parameter fixes are macro related.

 -Wswitch-default fixes fall-throughs in format parsing that
  would be caught during compilation by GCC (invalid formats).

 -Wdiscarded-qualifiers fixes add missing const around error messages
  which are usually literals.

 -Wincompatible-pointer-types, mem_prim_set32() takes a uint32_t* from
  wwmemset_s() wchar_t input without a cast.

Signed-off-by: Christopher Clark <christopher.w.cl...@gmail.com>
Patch is by Eric Chanudet for OpenXT:
https://github.com/OpenXT/xenclient-oe/blob/fc13893594f684baea65b7ee09066a8ddb840b4d/recipes-security/tboot/tboot-1.9.9/0014-safestringlib-Attend-GCC-warnings.patch

diff -r dcec96ce7d2c -r aed3b7861fb0 safestringlib/safeclib/abort_handler_s.c
--- a/safestringlib/safeclib/abort_handler_s.c  Fri Jan 24 10:03:42 2020 -0800
+++ b/safestringlib/safeclib/abort_handler_s.c  Fri Jan 24 10:10:20 2020 -0800
@@ -67,6 +67,7 @@
 
 void abort_handler_s(const char *msg, void *ptr, errno_t error)
 {
+       (void) ptr;
        slprintf("ABORT CONSTRAINT HANDLER: (%u) %s\n", error,
                 (msg) ? msg : "Null message");
        slabort();
diff -r dcec96ce7d2c -r aed3b7861fb0 safestringlib/safeclib/ignore_handler_s.c
--- a/safestringlib/safeclib/ignore_handler_s.c Fri Jan 24 10:03:42 2020 -0800
+++ b/safestringlib/safeclib/ignore_handler_s.c Fri Jan 24 10:10:20 2020 -0800
@@ -64,7 +64,9 @@
 
 void ignore_handler_s(const char *msg, void *ptr, errno_t error)
 {
-
+       (void) ptr;
+       (void) error;
+       (void) msg;
        sldebug_printf("IGNORE CONSTRAINT HANDLER: (%u) %s\n", error,
                       (msg) ? msg : "Null message");
        return;
diff -r dcec96ce7d2c -r aed3b7861fb0 
safestringlib/safeclib/safe_str_constraint.h
--- a/safestringlib/safeclib/safe_str_constraint.h      Fri Jan 24 10:03:42 
2020 -0800
+++ b/safestringlib/safeclib/safe_str_constraint.h      Fri Jan 24 10:10:20 
2020 -0800
@@ -48,12 +48,13 @@
  * Safe C Lib internal string routine to consolidate error handling
  */
 static inline void handle_error(char *orig_dest, rsize_t orig_dmax,
-                                char *err_msg, errno_t err_code)
+                                const char *err_msg, errno_t err_code)
 {
 #ifdef SAFECLIB_STR_NULL_SLACK
     /* null string to eliminate partial copy */
     while (orig_dmax) { *orig_dest = '\0'; orig_dmax--; orig_dest++; }
 #else
+    (void) orig_dmax;
     *orig_dest = '\0';
 #endif
 
@@ -62,12 +63,13 @@
 }
 
 static inline void handle_wc_error(wchar_t *orig_dest, rsize_t orig_dmax,
-                                char *err_msg, errno_t err_code)
+                                   const char *err_msg, errno_t err_code)
 {
 #ifdef SAFECLIB_STR_NULL_SLACK
     /* null string to eliminate partial copy */
     while (orig_dmax) { *orig_dest = L'\0'; orig_dmax--; orig_dest++; }
 #else
+    (void) orig_dmax;
     *orig_dest = L'\0';
 #endif
 
diff -r dcec96ce7d2c -r aed3b7861fb0 safestringlib/safeclib/snprintf_support.c
--- a/safestringlib/safeclib/snprintf_support.c Fri Jan 24 10:03:42 2020 -0800
+++ b/safestringlib/safeclib/snprintf_support.c Fri Jan 24 10:10:20 2020 -0800
@@ -78,6 +78,7 @@
                        case '+' : // force a sign be used
                                index++; // skip the flag character
                                break;
+                       default: break;
                        }
                        // check for and skip the optional field width
                        while ( format[index] != '\0' && format[index] >= '0' 
&& format[index] <= '9') {
@@ -112,6 +113,7 @@
                        case 'z' :
                        case 't' : index++;
                                   break;
+                       default: break;
                        }
 
                        // Recognize and record the actual modifier
@@ -212,6 +214,7 @@
                case FMT_INT   :
                        retValue = 1;
                        break;
+               default: break;
        }
        return retValue;
 }
diff -r dcec96ce7d2c -r aed3b7861fb0 safestringlib/safeclib/wmemset_s.c
--- a/safestringlib/safeclib/wmemset_s.c        Fri Jan 24 10:03:42 2020 -0800
+++ b/safestringlib/safeclib/wmemset_s.c        Fri Jan 24 10:10:20 2020 -0800
@@ -98,7 +98,7 @@
         return (RCNEGATE(ESLEMAX));
     }
 
-    mem_prim_set32(dest, len, value);
+    mem_prim_set32((void*)dest, len, value);
 
     return (RCNEGATE(EOK));
 }


_______________________________________________
tboot-devel mailing list
tboot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tboot-devel

Reply via email to