Skip to contentSkip to conversation

cups-1.7.0: job history fix

PATCH In review Tim Waugh 2 participants 4 messages Oct 25, 2013 – Oct 28, 2013

lore
Share & tools
lore

Tim Waugh

author
#0 lore raw

PATCH 1/1 cups-1.7.0: job history fix

Hi,

While playing around with a logging enhancement¹ I discovered a bug in the job history code. It was introduced some time after the public source repository was taken off-line, so I don't know what the motivation for the change was.

A cups_joblog_t declares 'char message[1]' for the message, and is allocated with enough storage for the intended message. However, the message is copied in with strlcpy, with a limit of sizeof(cups_joblog_t->message). As a result, the message is severely(!) truncated.

The fix is to undo the change as attached.

Tim.
*/

¹ http://cyberelk.net/tim/2013/10/25/cups-adding-support-for-system-journal/

scheduler/log.c renamed from scheduler/log.c.orig +1 -1
diff -up cups-1.7rc1/scheduler/log.c.orig cups-1.7rc1/scheduler/log.c
@@ -534,7 +534,7 @@ cupsdLogJob(cupsd_job_t *job,		/* I - Jo
       if ((temp = malloc(sizeof(cupsd_joblog_t) + strlen(log_line))) != NULL)
       {
         temp->time = time(NULL);
-	strlcpy(temp->message, log_line, sizeof(temp->message));
+	strcpy(temp->message, log_line);
       }
 
       if (!job->history)
#1 lore raw

Tim,

Thanks, I filed this as:

<rdar://problem/15331639> cups.org: Regression in auto-debug logging

That said, your proposed fix actually isn't safe either - the Fortify strcpy stuff in glibc effectively converts the strcpy to a strlcpy, so the code will break if you happen to compile using the -D_FORTIFY_SOURCE=2 compiler option.

I will follow up with a memcpy-based fix.

Thanks for reporting this!

(and we are 1 electronic signature away from getting cups.org's bug tracker back online...)

Quoted 15 lines · Tim Waugh

Hi,

While playing around with a logging enhancement¹ I discovered a bug in the job history code. It was introduced some time after the public source repository was taken off-line, so I don't know what the motivation for the change was.

A cups_joblog_t declares 'char message[1]' for the message, and is allocated with enough storage for the intended message. However, the message is copied in with strlcpy, with a limit of sizeof(cups_joblog_t->message). As a result, the message is severely(!) truncated.

The fix is to undo the change as attached.

Quoted 8 lines

Tim.
*/

¹ http://cyberelk.net/tim/2013/10/25/cups-adding-support-for-system-journal/
<cups-jobhistory.patch>_______________________________________________ Printing-architecture mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/printing-architecture

_________________________________________________________
Michael Sweet, Senior Printing System Engineer, PWG Chair

#2 lore raw

and here is the fix:

log.c +4 -3
Index: scheduler/log.c
===================================================================
@@ -541,12 +541,13 @@
       */
 
       cupsd_joblog_t *temp;		/* Copy of log message */
+      size_t         log_len = strlen(log_line);
+					/* Length of log message */
 
-
-      if ((temp = malloc(sizeof(cupsd_joblog_t) + strlen(log_line))) != NULL)
+      if ((temp = malloc(sizeof(cupsd_joblog_t) + log_len)) != NULL)
       {
         temp->time = time(NULL);
-	strlcpy(temp->message, log_line, sizeof(temp->message));
+	memcpy(temp->message, log_line, log_len + 1);
       }
 
       if (!job->history)
Quoted 41 lines · Michael Sweet

Tim,

Thanks, I filed this as:

<rdar://problem/15331639> cups.org: Regression in auto-debug logging

That said, your proposed fix actually isn't safe either - the Fortify strcpy stuff in glibc effectively converts the strcpy to a strlcpy, so the code will break if you happen to compile using the -D_FORTIFY_SOURCE=2 compiler option.

I will follow up with a memcpy-based fix.

Thanks for reporting this!

(and we are 1 electronic signature away from getting cups.org's bug tracker back online...)

Quoted 15 lines · Tim Waugh

Hi,

While playing around with a logging enhancement¹ I discovered a bug in the job history code. It was introduced some time after the public source repository was taken off-line, so I don't know what the motivation for the change was.

A cups_joblog_t declares 'char message[1]' for the message, and is allocated with enough storage for the intended message. However, the message is copied in with strlcpy, with a limit of sizeof(cups_joblog_t->message). As a result, the message is severely(!) truncated.

The fix is to undo the change as attached.

Quoted 8 lines

Tim.
*/

¹ http://cyberelk.net/tim/2013/10/25/cups-adding-support-for-system-journal/
<cups-jobhistory.patch>_______________________________________________ Printing-architecture mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/printing-architecture

Quoted 7 lines

_________________________________________________________
Michael Sweet, Senior Printing System Engineer, PWG Chair

_______________________________________________
Printing-architecture mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/printing-architecture

_________________________________________________________
Michael Sweet, Senior Printing System Engineer, PWG Chair

author
#3 lore raw
Quoted 1 line · Michael Sweet

and here is the fix:

Thanks.

Tim.
*/