Sophie

Sophie

distrib > Mageia > 9 > armv7hl > media > core-release-src > by-pkgid > 34d3007addba92609f3094d96935b9f6 > files > 6

hplip-3.22.10-4.mga9.src.rpm

diff -up hplip-3.22.10/protocol/hp_ipp.c.fix hplip-3.22.10/protocol/hp_ipp.c
--- hplip-3.22.10/protocol/hp_ipp.c.fix	2022-10-27 15:08:44.000000000 +0200
+++ hplip-3.22.10/protocol/hp_ipp.c	2023-04-27 16:26:42.873735958 +0200
@@ -40,6 +40,12 @@ Boston, MA 02110-1301, USA.
 #define _STRINGIZE(x) #x
 #define STRINGIZE(x) _STRINGIZE(x)
 
+#define hplip_strlcpy(dst, src, size) \
+    do { \
+        if (!memccpy(dst, src, '\0', size)) \
+		dst[size - 1] = '\0'; \
+    } while (0)
+
 
 http_t* acquireCupsInstance()
 {
@@ -110,7 +116,7 @@ int addCupsPrinter(char *name, char *dev
      }
 
      if ( info == NULL )
-        snprintf( info,sizeof(info), name );
+        hplip_strlcpy( info, name, sizeof(info));
 
      sprintf( printer_uri, "ipp://localhost/printers/%s", name );
 
@@ -511,27 +517,27 @@ int __parsePrinterAttributes(ipp_t *resp
 
              if ( strcmp(attr_name, "printer-name") == 0 &&
                                         val_tag == IPP_TAG_NAME ) {
-                  snprintf(t_printer->name, sizeof(t_printer->name),ippGetString(attr, 0, NULL) );
+                  hplip_strlcpy(t_printer->name, ippGetString(attr, 0, NULL), sizeof(t_printer->name) );
              }
              else if ( strcmp(attr_name, "device-uri") == 0 &&
                                          val_tag == IPP_TAG_URI ) {
-                  snprintf(t_printer->device_uri,sizeof(t_printer->device_uri), ippGetString(attr, 0, NULL) );
+                  hplip_strlcpy(t_printer->device_uri, ippGetString(attr, 0, NULL), sizeof(t_printer->device_uri) );
              }
              else if ( strcmp(attr_name, "printer-uri-supported") == 0 &&
                                                  val_tag == IPP_TAG_URI ) {
-                  snprintf(t_printer->printer_uri,sizeof(t_printer->printer_uri), ippGetString(attr, 0, NULL) );
+                  hplip_strlcpy(t_printer->printer_uri, ippGetString(attr, 0, NULL), sizeof(t_printer->printer_uri) );
              }
              else if ( strcmp(attr_name, "printer-info") == 0 &&
                                         val_tag == IPP_TAG_TEXT ) {
-                  snprintf(t_printer->info,sizeof(t_printer->info), ippGetString(attr, 0, NULL) );
+                  hplip_strlcpy(t_printer->info, ippGetString(attr, 0, NULL), sizeof(t_printer->info) );
              }
              else if ( strcmp(attr_name, "printer-location") == 0 &&
                                            val_tag == IPP_TAG_TEXT ) {
-                  snprintf(t_printer->location,sizeof(t_printer->location),ippGetString(attr, 0, NULL) );
+                  hplip_strlcpy(t_printer->location, ippGetString(attr, 0, NULL), sizeof(t_printer->location) );
              }
              else if ( strcmp(attr_name, "printer-make-and-model") == 0 &&
                                                   val_tag == IPP_TAG_TEXT ) {
-                  snprintf(t_printer->make_model,sizeof(t_printer->make_model),ippGetString(attr, 0, NULL) );
+                  hplip_strlcpy(t_printer->make_model, ippGetString(attr, 0, NULL), sizeof(t_printer->make_model));
              } 
              else if ( strcmp(attr_name, "printer-state") == 0 &&
                                              val_tag == IPP_TAG_ENUM ) {